﻿using DX_Recognize.Common;
using DX_Recognize.Entitys;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Windows.Forms;
using ZwSoft.ZwCAD.DatabaseServices.Filters;


namespace DX_Recognize.Utils
{
    //数据库落数 & 数据 坐标转换 
    public class ConvertUtils
    {
        public ComputedUtils CU = new ComputedUtils();
        //Process Auto Type Upload Haring To Do
        public Boolean ATypeUploadHaringData()
        {
            Boolean SMoldF = false;
            if (ParamsConfigData.MoldHoleList.Count > 0)
            {
                string nowMoldSizeFormat = ComputedUtils.ATypeGetMoldSizeFormat();
                List<int> moldSizeIntList = ParamsConfigData.MoldHoleList.Select(item => item.MouldSize).ToList();
                moldSizeIntList = moldSizeIntList.Distinct().ToList();
                if (moldSizeIntList.Count > 0)
                {
                    List<string> moldSizeList = new List<string>();
                    moldSizeIntList.ForEach(item => moldSizeList.Add(item.ToString()));
                    if (moldSizeList.Count > 0)
                    {
                        SMoldF = moldSizeList.Contains(nowMoldSizeFormat);
                    }
                }
            }
            return SMoldF;

        }

        //转换 数据库加工孔数据 & ERP上送数据
        public ProcessData ATypeTransToPHoleAndERPData(ModeBasicData PBasicData)
        {
            ProcessData ResData = new ProcessData();
            try
            {
                //Basic Info
                ResData.BasicData.Customer = PBasicData.Customer;
                ResData.BasicData.BatchNum = PBasicData.BatchNum;
                ResData.BasicData.ModeNum = PBasicData.ModeNum;
                ResData.BasicData.FancyType = PBasicData.FancyType;
                ResData.BasicData.ModeSize = PBasicData.ModeSize;
                ResData.BasicData.JobNumber = PBasicData.JobNumber;
                ResData.BasicData.tempOrderNumber = PBasicData.tempOrderNumber;
                //Extra ERP Info
                ResData.ExtrajudgeInfo.gpRevFlag = ShareItemBoardShipInfo.extraShipInfo.gpRevFlag;
                ResData.ExtrajudgeInfo.rpOverSpFlag = ShareItemBoardShipInfo.extraShipInfo.rpOverSpFlag;
                ResData.ExtrajudgeInfo.gpOverSpFlag = ShareItemBoardShipInfo.extraShipInfo.gpOverSpFlag;
                List<ProcessBoard> PBoardList = new List<ProcessBoard>();
                // 精框数据
                List<FrameItem> FrameList = new List<FrameItem>();
                // 孔加工数据
                List<HoleMould> CHoleMouldList = new List<HoleMould>();
                List<ItemBaseParamData> PrItemList = new List<ItemBaseParamData>();
                // 板坐标信息
                List<BoardCoordinateInfo> BoardCoorList = new List<BoardCoordinateInfo>();
                MixedCAD_Point modlHInfo = RecognizeUtils.WholeTopViewData.ModlCenterInfo;
                double RefX = modlHInfo.CustomerPoint.X;
                double RefY = modlHInfo.CustomerPoint.Y;
                double BoardL = MoldBaseShare.Length;
                //识别的板 数据全
                List<BoardSectionItem> UIBoardDataList = AssemblyShareData.AUIBlueSectionList;
                Boolean SMoldF = ATypeUploadHaringData();
                for (int i = 0; i < UIBoardDataList.Count; i++)
                {
                    ProcessBoard PBItem = new ProcessBoard();
                    PBItem.BoardUID = UIBoardDataList[i].BoardUID;
                    PBItem.BoardCode = UIBoardDataList[i].BoardCode;
                    PBItem.Seq_no = UIBoardDataList[i].plateLineNo;
                    PBItem.Plate_Name = UIBoardDataList[i].BoardName;
                    PBItem.Steel_Desc = UIBoardDataList[i].Steel.SteelName;
                    PBItem.Steel_Code = UIBoardDataList[i].Steel.SteelCode;
                    PBItem.Thickness = UIBoardDataList[i].PlateThick;
                    PBItem.Width = UIBoardDataList[i].PlateWidth;
                    PBItem.Length = UIBoardDataList[i].PlateLength;
                    PBItem.Qty = UIBoardDataList[i].Num;
                    PBItem.LaringNum = UIBoardDataList[i].Hanging.Num;
                    PBItem.LaringDim = UIBoardDataList[i].Hanging.HangingParam.Dim;
                    PBItem.Remark = UIBoardDataList[i].UIRemark;
                    if (PBItem.Remark == null)
                        PBItem.Remark = "";
                    //这里没有考虑中托司
                    if (UIBoardDataList[i].PitchHoleStandard == StandardType.Standard)
                        PBItem.Standard_Plate = true;
                    if (UIBoardDataList[i].PitchHoleStandard == StandardType.NonStandard)
                        PBItem.Standard_Plate = false;
                    //Pulling affects warehouse withdrawal Logic
                    if (SMoldF)
                    {
                        StandardType targetHType = UIBoardDataList[i].Hanging.standardType;
                        if (targetHType == StandardType.Standard || targetHType == StandardType.Untried)
                            PBItem.Standard_Laring = true;
                        if (targetHType == StandardType.NonStandard)
                            PBItem.Standard_Laring = false;
                    }
                    else
                        PBItem.Standard_Laring = false;
                    PBoardList.Add(PBItem);

                    BoardCoordinateInfo Item = new BoardCoordinateInfo();
                    Item.BoardUID = UIBoardDataList[i].BoardUID;
                    Item.plate_X0 = UIBoardDataList[i].ProBCPoint.X;
                    Item.plate_Y0 = 0;
                    Item.plate_Z0 = UIBoardDataList[i].ProBCPoint.Z;
                    if (UIBoardDataList[i].BoardCode.Equals("fangtie"))
                        Item.CenterX = UIBoardDataList[i].ProBCPoint.X;
                    BoardCoorList.Add(Item);
                    if (UIBoardDataList[i].frameItem.BoardUID != null)
                        FrameList.Add(UIBoardDataList[i].frameItem);
                }

                //板加工正反面
                List<BoardSectionItem> BoardDataList = AssemblyShareData.ASectionList;
                if (BoardDataList.Count > 0)
                {
                    for (int i = 0; i < BoardDataList.Count; i++)
                    {
                        HoleMould HItem1 = new HoleMould();
                        HItem1.plate_name = BoardDataList[i].BoardName;
                        HItem1.BoardCode = BoardDataList[i].BoardCode;
                        HItem1.BoardUID = BoardDataList[i].BoardUID;
                        HItem1.L = Convert.ToDecimal(BoardL);
                        HItem1.W = Convert.ToDecimal(BoardDataList[i].PlateWidth);
                        HItem1.H = Convert.ToDecimal(BoardDataList[i].PlateThick);
                        HItem1.plate_X0 = (Decimal)BoardDataList[i].ProBCPoint.X;
                        HItem1.plate_Y0 = (Decimal)BoardDataList[i].ProBCPoint.Y;
                        HItem1.plate_Z0 = (Decimal)BoardDataList[i].ProBCPoint.Z;
                        HItem1.Bat = BoardDataList[i].Steel.SteelName;
                        HItem1.Plate_Sur = "正面";
                        HItem1.plate_LineNo = BoardDataList[i].plateLineNo;
                        if (BoardDataList[i].extraFInfo.FFlag)
                            HItem1.fPosType = BoardDataList[i].extraFInfo.fPosType;
                        CHoleMouldList.Add(HItem1);
                        HoleMould HItem2 = new HoleMould();
                        HItem2.plate_name = BoardDataList[i].BoardName;
                        HItem2.BoardCode = BoardDataList[i].BoardCode;
                        HItem2.BoardUID = BoardDataList[i].BoardUID;
                        HItem2.L = Convert.ToDecimal(BoardL);
                        HItem2.W = Convert.ToDecimal(BoardDataList[i].PlateWidth);
                        HItem2.H = Convert.ToDecimal(BoardDataList[i].PlateThick);
                        HItem2.plate_X0 = (Decimal)BoardDataList[i].ProBCPoint.X;
                        HItem2.plate_Y0 = (Decimal)BoardDataList[i].ProBCPoint.Y;
                        HItem2.plate_Z0 = (Decimal)BoardDataList[i].ProBCPoint.Z;
                        HItem2.Bat = BoardDataList[i].Steel.SteelName;
                        HItem2.Plate_Sur = "反面";
                        HItem2.plate_LineNo = BoardDataList[i].plateLineNo;
                        if (BoardDataList[i].extraFInfo.FFlag)
                            HItem2.fPosType = BoardDataList[i].extraFInfo.fPosType;
                        CHoleMouldList.Add(HItem2);
                    }
                }

                //将板坐标和正反面信息整合 plate_Z0 -板Z坐标
                for (int i = 0; i < CHoleMouldList.Count; i++)
                {
                    BoardCoordinateInfo tempCoorItem = BoardCoorList.Find(item => item.BoardUID.Equals(CHoleMouldList[i].BoardUID));
                    if (tempCoorItem != null)
                        CHoleMouldList[i].CenterX = Math.Round(tempCoorItem.CenterX, 2);
                }

                //界面UI的识别零件信息
                List<SingleItem> ItemList = ShareItemData.UIItemList;
                if (CHoleMouldList.Count > 0)
                {
                    //板正反数据 和零件孔关联起来(1板N孔)
                    for (int i = 0; i < ItemList.Count; i++)
                    {
                        ItemBaseParamData PrItem = new ItemBaseParamData();
                        PrItem.ItemName = ItemList[i].ItemName;
                        PrItem.ItemType = (int)ItemList[i].ItemNameType;
                        PrItem.SortNo = CU.SetSortByItemNameType(ItemList[i].ItemNameType);
                        PrItem.Remark = ItemList[i].Remark;

                        //处理中托司||中托边(上传理论长度)
                        if (JudgeAboutEGP(ItemList[i].ItemNameType))
                        {
                            double diffH = 0;
                            diffH += BoardDataList[BoardDataList.Count - 1].PlateThick;
                            int fangtieIndex = BoardDataList.FindIndex(item => item.BoardCode.Equals("fangtie"));
                            if (fangtieIndex != -1)
                                diffH += BoardDataList[fangtieIndex].PlateThick;
                            double BlindH = ItemList[i].TheoryH - diffH;
                            double tempBlindH = ComputedUtils.ProcessEGPBlindDepth(ItemList[i]);
                            if(tempBlindH != 0)
                                BlindH = tempBlindH;
                            Boolean egpF = ItemList[i].ItemNameType == DItemNameType.EGPPin;
                            Boolean egpBushF = ItemList[i].ItemNameType == DItemNameType.EGPBush;
                            if (egpF)
                            {
                                string PlateSur = "反面";
                                BoardSectionItem TDBoard = ItemList[i].TDBoard;
                                BoardSectionItem BlindBoard = ItemList[i].BlindHoleBoard;
                                if(TDBoard.BoardCode != null)
                                {
                                    HoleData TDItem = ATypeBuildScrewHoleByItem(ItemList[i], HoleProcessType.Sinkhead);
                                    TDItem.LineNo = ItemList[i].lineNo;
                                    int tdBIndex = CHoleMouldList.FindIndex(item => item.Plate_Sur.Equals(PlateSur)
                                        && item.BoardUID.Equals(TDBoard.BoardUID));
                                    if (tdBIndex != -1)
                                    {
                                        List<StandardHoleData> SHoleList = ItemList[i].HSplitInfo.SplitInfoList;
                                        for (int k = 0; k < SHoleList.Count; k++)
                                        {
                                            HPoint2D HPItem = new HPoint2D();
                                            HPItem.HoleName = CU.SetItemNameByType(ItemList[i].ItemNameType);
                                            HPItem.X = Convert.ToDecimal(SHoleList[k].ItemX);
                                            HPItem.X = Math.Round(HPItem.X, 2);
                                            HPItem.Y = Convert.ToDecimal(SHoleList[k].ItemY);
                                            HPItem.Y = Math.Round(HPItem.Y, 2);
                                            HPItem.Z0 = 0;
                                            HPItem.Z1 = Convert.ToDecimal(TDBoard.PlateThick);
                                            TDItem.HPointList.Add(HPItem);
                                        }
                                        CHoleMouldList[tdBIndex].HoleDataList.Add(TDItem);
                                    }
                                }
                                if(BlindBoard.BoardCode != null)
                                {
                                    HoleData BlindItem = ATypeBuildScrewHoleByItem(ItemList[i], HoleProcessType.BlindHole);
                                    BlindItem.LineNo = ItemList[i].lineNo;
                                    int tdBIndex = CHoleMouldList.FindIndex(item => item.Plate_Sur.Equals(PlateSur)
                                        && item.BoardUID.Equals(BlindBoard.BoardUID));
                                    if (tdBIndex != -1)
                                    {
                                        List<StandardHoleData> SHoleList = ItemList[i].HSplitInfo.SplitInfoList;
                                        for (int k = 0; k < SHoleList.Count; k++)
                                        {
                                            HPoint2D HPItem = new HPoint2D();
                                            HPItem.HoleName = CU.SetItemNameByType(ItemList[i].ItemNameType);
                                            HPItem.X = Convert.ToDecimal(SHoleList[k].ItemX);
                                            HPItem.X = Math.Round(HPItem.X, 2);
                                            HPItem.Y = Convert.ToDecimal(SHoleList[k].ItemY);
                                            HPItem.Y = Math.Round(HPItem.Y, 2);
                                            HPItem.Z0 = 0;
                                            HPItem.Z1 = Convert.ToDecimal(BlindH);
                                            BlindItem.HPointList.Add(HPItem);
                                        }
                                        CHoleMouldList[tdBIndex].HoleDataList.Add(BlindItem);
                                    }
                                }
                            }
                            if(egpBushF)
                            {
                                BoardSectionItem BushTDBoard = ItemList[i].BushTDBoard;
                                //EGP Bush 沉头孔
                                if (BushTDBoard.BoardUID != null)
                                {
                                    HoleData BushTDItem = ATypeBuildScrewHoleByItem(ItemList[i], HoleProcessType.Sinkhead);
                                    BushTDItem.LineNo = ItemList[i].lineNo;
                                    string PlateSur = "正面";
                                    int tdBIndex = CHoleMouldList.FindIndex(item => item.Plate_Sur.Equals(PlateSur)
                                        && item.BoardUID.Equals(BushTDBoard.BoardUID));
                                    if (tdBIndex != -1)
                                    {
                                        List<StandardHoleData> SHoleList = ItemList[i].HSplitInfo.SplitInfoList;

                                        for (int k = 0; k < SHoleList.Count; k++)
                                        {
                                            HPoint2D HPItem = new HPoint2D();
                                            HPItem.HoleName = CU.SetItemNameByType(ItemList[i].ItemNameType);
                                            HPItem.X = Convert.ToDecimal(SHoleList[k].ItemX);
                                            HPItem.X = Math.Round(HPItem.X, 2);
                                            HPItem.Y = Convert.ToDecimal(SHoleList[k].ItemY);
                                            HPItem.Y = Math.Round(HPItem.Y, 2);
                                            HPItem.Z0 = 0;
                                            HPItem.Z1 = Convert.ToDecimal(BushTDBoard.PlateThick);
                                            BushTDItem.HPointList.Add(HPItem);
                                        }
                                        CHoleMouldList[tdBIndex].HoleDataList.Add(BushTDItem);
                                    }
                                }

                                //EGP Bush 通孔
                                List<BoardSectionItem> BushSizeList = ItemList[i].BushBoardList;
                                if(BushSizeList.Count > 0)
                                {
                                    HoleData BushTDItem = ATypeBuildScrewHoleByItem(ItemList[i], HoleProcessType.ThroughHole);
                                    BushTDItem.LineNo = ItemList[i].lineNo;
                                    string PlateSur = "反面";
                                    for (int z = 0; z < BushSizeList.Count; z++)
                                    {
                                        int bushBIndex = CHoleMouldList.FindIndex(item => item.Plate_Sur.Equals(PlateSur)
                                        && item.BoardUID.Equals(BushSizeList[z].BoardUID));
                                        if(bushBIndex != -1)
                                        {
                                            List<StandardHoleData> SHoleList = ItemList[i].HSplitInfo.SplitInfoList;

                                            for (int k = 0; k < SHoleList.Count; k++)
                                            {
                                                HPoint2D HPItem = new HPoint2D();
                                                HPItem.HoleName = CU.SetItemNameByType(ItemList[i].ItemNameType);
                                                HPItem.X = Convert.ToDecimal(SHoleList[k].ItemX);
                                                HPItem.X = Math.Round(HPItem.X, 2);
                                                HPItem.Y = Convert.ToDecimal(SHoleList[k].ItemY);
                                                HPItem.Y = Math.Round(HPItem.Y, 2);
                                                HPItem.Z0 = 0;
                                                HPItem.Z1 = Convert.ToDecimal(BushSizeList[z].PlateThick);
                                                BushTDItem.HPointList.Add(HPItem);
                                            }
                                            CHoleMouldList[bushBIndex].HoleDataList.Add(BushTDItem);
                                        }
                                    }
                                }
                                
                            }

                            if (ItemList[i].TheoryH != 0)
                                PrItem.Length = ItemList[i].TheoryH;
                            PrItem.Dim = ItemList[i].Dim;
                            if (ItemList[i].ItemNum != null)
                                PrItem.Num = (int)ItemList[i].ItemNum;
                        }

                        //处理螺丝
                        else
                        if (JudgeItemTypeIsScrew(ItemList[i].ItemNameType))
                        {
                            Boolean ProcessF= ItemList[i].ItemCode.Contains("Screw") && !ItemList[i].ItemCode.Equals("MesonScrew");
                            if(ProcessF)
                                ComputedUtils.PreProcessScrewData(ItemList[i]);
                            //螺丝给理论
                            PrItem.Length = ItemList[i].TheoryScrewH;
                            PrItem.Dim = ItemList[i].Dim;
                            if (ItemList[i].ItemNum != null)
                                PrItem.Num = (int)ItemList[i].ItemNum;

                            //处理螺丝盲牙孔
                            if (ItemList[i].BlindHoleBoard.BoardCode != null)
                            {
                                InBoardPosType TDType = ItemList[i].TDPosType;
                                UnloadMoldPosType TDunloadPostType = UnloadMoldPosType.NONE;
                                if (ItemList[i].TDBoard.BoardUID != null)
                                    TDunloadPostType = ItemList[i].TDBoard.withaBoardPosType;
                                BoardSectionItem NPBoard = new BoardSectionItem();
                                string PlateSur = null;
                                //正反面的板数据
                                int ToochMouldIndex = -1;
                                if (TDType == InBoardPosType.BoardUp)
                                {
                                    NPBoard = ItemList[i].BlindHoleBoard;
                                    if (TDunloadPostType == UnloadMoldPosType.aBoardUp)
                                        PlateSur = "反面";
                                    if (TDunloadPostType == UnloadMoldPosType.aBoardDown)
                                        PlateSur = "正面";
                                }
                                if (TDType == InBoardPosType.BoardDown)
                                {
                                    NPBoard = ItemList[i].BlindHoleBoard;
                                    if (TDunloadPostType == UnloadMoldPosType.aBoardUp)
                                        PlateSur = "正面";
                                    if (TDunloadPostType == UnloadMoldPosType.aBoardDown)
                                        PlateSur = "反面";
                                }
                                if (NPBoard.BoardUID != null)
                                {
                                    if (NPBoard.BoardUID.Contains("fangtie"))
                                    {
                                        //RL方铁都+
                                        List<HoleMould> RLFList = CHoleMouldList.FindAll(item => item.Plate_Sur.Equals("反面")
                                        && item.BoardCode.Equals("fangtie"));
                                        if (RLFList.Count > 0)
                                        {
                                            for (int j = 0; j < RLFList.Count; j++)
                                            {
                                                //螺丝盲牙孔深度 = 理论长度 - 通孔板厚度 - 托位板厚度
                                                HoleData HDItem = ATypeBuildScrewHoleByItem(ItemList[i], HoleProcessType.BlindScrew);
                                                HDItem.LineNo = ItemList[i].lineNo;
                                                List<StandardHoleData> SHoleList = ItemList[i].HSplitInfo.SplitInfoList;
                                                for (int k = 0; k < SHoleList.Count; k++)
                                                {
                                                    if (RLFList[j].fPosType == SHoleList[k].fPosType)
                                                    {
                                                        HPoint2D HPItem = new HPoint2D();
                                                        HPItem.HoleName = CU.SetItemNameByType(ItemList[i].ItemNameType);
                                                        HPItem.X = Convert.ToDecimal(SHoleList[k].ItemX - (double)RLFList[j].plate_X0);
                                                        HPItem.X = Math.Round(HPItem.X, 2);
                                                        HPItem.Y = Convert.ToDecimal(SHoleList[k].ItemY);
                                                        HPItem.Y = Math.Round(HPItem.Y, 2);
                                                        HPItem.Z0 = 0;
                                                        double ThroughBListThick = ItemList[i].ScrewDimThroughHBList.Sum(item => item.PlateThick);
                                                        double TDBThick = ItemList[i].TDBoard.PlateThick;
                                                        Boolean toochF = ItemList[i].ToochInfo.ExistTheTip;
                                                        //double BlindH = ItemList[i].TheoryScrewH - ThroughBListThick - TDBThick + (double)ItemList[i].TH;
                                                        //if (toochF)
                                                        double BlindH = ItemList[i].ToochInfo.ProcessBlindToochH;
                                                        // TO Check
                                                        HPItem.Z1 = Math.Round(Convert.ToDecimal(BlindH), 0);
                                                        HDItem.HPointList.Add(HPItem);
                                                    }
                                                }
                                                int FMouldIndex = CHoleMouldList.FindIndex(item => item.BoardUID.Equals(RLFList[j].BoardUID)
                                                && item.Plate_Sur.Equals("反面"));
                                                if (FMouldIndex != -1)
                                                    CHoleMouldList[FMouldIndex].HoleDataList.Add(HDItem);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        ToochMouldIndex = CHoleMouldList.FindIndex(item => item.Plate_Sur.Equals(PlateSur)
                                        && item.BoardUID.Equals(NPBoard.BoardUID));
                                        //盲牙孔
                                        HoleData HDItem = ATypeBuildScrewHoleByItem(ItemList[i], HoleProcessType.BlindScrew);
                                        HDItem.LineNo = ItemList[i].lineNo;
                                        if (ToochMouldIndex != -1)
                                        {
                                            List<StandardHoleData> SHoleList = ItemList[i].HSplitInfo.SplitInfoList;
                                            for (int k = 0; k < SHoleList.Count; k++)
                                            {
                                                HPoint2D HPItem = new HPoint2D();
                                                HPItem.HoleName = CU.SetItemNameByType(ItemList[i].ItemNameType);
                                                HPItem.X = Convert.ToDecimal(SHoleList[k].ItemX);
                                                HPItem.X = Math.Round(HPItem.X, 2);
                                                HPItem.Y = Convert.ToDecimal(SHoleList[k].ItemY);
                                                HPItem.Y = Math.Round(HPItem.Y, 2);
                                                HPItem.Z0 = 0;
                                                double ThroughBListThick = ItemList[i].ScrewDimThroughHBList.Sum(item => item.PlateThick);
                                                double TDBThick = ItemList[i].TDBoard.PlateThick;
                                                //Boolean toochF = ItemList[i].ToochInfo.ExistTheTip;
                                                //double BlindH = ItemList[i].TheoryScrewH - ThroughBListThick - TDBThick + (double)ItemList[i].TH;
                                                //if (toochF)
                                                    double BlindH = ItemList[i].ToochInfo.ProcessBlindToochH;
                                                HPItem.Z1 = Math.Round(Convert.ToDecimal(BlindH), 0);
                                                HDItem.HPointList.Add(HPItem);
                                            }
                                            CHoleMouldList[ToochMouldIndex].HoleDataList.Add(HDItem);
                                        }
                                    }
                                }
                            }

                            //处理螺丝托位(沉头孔)
                            if (ItemList[i].TDPosType != InBoardPosType.NONE)
                            {
                                BoardSectionItem TDBoard = ItemList[i].TDBoard;
                                InBoardPosType TDType = ItemList[i].TDPosType;
                                UnloadMoldPosType TDunloadPostType = UnloadMoldPosType.NONE;
                                if (TDBoard.BoardUID != null)
                                    TDunloadPostType = TDBoard.withaBoardPosType;

                                string PlateSur = null;
                                if (TDType == InBoardPosType.BoardUp)
                                {
                                    if (TDunloadPostType == UnloadMoldPosType.aBoardUp)
                                        PlateSur = "反面";
                                    if (TDunloadPostType == UnloadMoldPosType.aBoardDown)
                                        PlateSur = "正面";
                                }
                                if (TDType == InBoardPosType.BoardDown)
                                {
                                    if (TDunloadPostType == UnloadMoldPosType.aBoardUp)
                                        PlateSur = "正面";
                                    if (TDunloadPostType == UnloadMoldPosType.aBoardDown)
                                        PlateSur = "反面";
                                }

                                if (!(TDBoard.BoardCode is null))
                                {
                                    if (TDBoard.BoardCode.Equals("fangtie"))
                                    {
                                        //RL方铁都+
                                        List<HoleMould> RLFList = CHoleMouldList.FindAll(item => item.Plate_Sur.Equals(PlateSur)
                                        && item.BoardCode.Equals("fangtie"));
                                        if (RLFList.Count > 0)
                                        {
                                            for (int j = 0; j < RLFList.Count; j++)
                                            {
                                                HoleData HDItem = ATypeBuildScrewHoleByItem(ItemList[i], HoleProcessType.Sinkhead);
                                                HDItem.LineNo = ItemList[i].lineNo;
                                                List<StandardHoleData> SHoleList = ItemList[i].HSplitInfo.SplitInfoList;
                                                for (int k = 0; k < SHoleList.Count; k++)
                                                {
                                                    if (RLFList[j].fPosType == SHoleList[k].fPosType)
                                                    {
                                                        HPoint2D HPItem = new HPoint2D();
                                                        HPItem.HoleName = CU.SetItemNameByType(ItemList[i].ItemNameType);
                                                        HPItem.X = Convert.ToDecimal(Convert.ToDecimal(SHoleList[k].ItemX)
                                                            - Convert.ToDecimal(RLFList[j].plate_X0));
                                                        HPItem.X = Math.Round(HPItem.X, 2);
                                                        HPItem.Z0 = 0;
                                                        HPItem.Z1 = Convert.ToDecimal(TDBoard.PlateThick);
                                                        HDItem.HPointList.Add(HPItem);
                                                    }
                                                }
                                                int FMouldIndex = CHoleMouldList.FindIndex(item => item.BoardUID.Equals(RLFList[j].BoardUID)
                                                && item.Plate_Sur.Equals(PlateSur));
                                                if (FMouldIndex != -1)
                                                    CHoleMouldList[FMouldIndex].HoleDataList.Add(HDItem);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        HoleData TDItem = ATypeBuildScrewHoleByItem(ItemList[i], HoleProcessType.Sinkhead);
                                        TDItem.LineNo = ItemList[i].lineNo;
                                        int TDIndex = CHoleMouldList.FindIndex(item => item.Plate_Sur.Equals(PlateSur)
                                        && item.BoardUID.Equals(TDBoard.BoardUID));
                                        if (TDIndex != -1)
                                        {
                                            List<StandardHoleData> SHoleList = ItemList[i].HSplitInfo.SplitInfoList;
                                            for (int k = 0; k < SHoleList.Count; k++)
                                            {
                                                HPoint2D HPItem = new HPoint2D();
                                                HPItem.HoleName = CU.SetItemNameByType(ItemList[i].ItemNameType);
                                                HPItem.X = Convert.ToDecimal(SHoleList[k].ItemX);
                                                HPItem.X = Math.Round(HPItem.X, 2);
                                                HPItem.Y = Convert.ToDecimal(SHoleList[k].ItemY);
                                                HPItem.Y = Math.Round(HPItem.Y, 2);
                                                HPItem.Z0 = 0;
                                                HPItem.Z1 = Convert.ToDecimal(TDBoard.PlateThick);
                                                TDItem.HPointList.Add(HPItem);
                                            }
                                            CHoleMouldList[TDIndex].HoleDataList.Add(TDItem);
                                        }
                                    }
                                }
                            }

                            //处理螺丝通孔
                            List<BoardSectionItem> TempDimPBList = new List<BoardSectionItem>(ItemList[i].ScrewDimThroughHBList);
                            if (TempDimPBList.Count > 0)
                            {
                                //处理通孔 一律默认是反面加工
                                for (int j = 0; j < TempDimPBList.Count; j++)
                                {
                                    if (TempDimPBList[j].BoardCode.Equals("fangtie"))
                                    {
                                        //RL方铁都+  TO F 
                                        List<HoleMould> RLFList = CHoleMouldList.FindAll(item => item.Plate_Sur.Equals("反面")
                                        && item.BoardCode.Equals("fangtie"));
                                        if (RLFList.Count > 0)
                                        {
                                            for (int k = 0; k < RLFList.Count; k++)
                                            {
                                                //通孔
                                                HoleData HDItem = ATypeBuildScrewHoleByItem(ItemList[i], HoleProcessType.ThroughHole);
                                                HDItem.LineNo = ItemList[i].lineNo;
                                                int FMouldIndex = CHoleMouldList.FindIndex(item => item.BoardUID.Equals(RLFList[k].BoardUID)
                                                && item.Plate_Sur.Equals("反面"));
                                                if (FMouldIndex != -1)
                                                {
                                                    List<StandardHoleData> SHoleList = ItemList[i].HSplitInfo.SplitInfoList;
                                                    for (int l = 0; l < SHoleList.Count; l++)
                                                    {
                                                        if (RLFList[k].fPosType == SHoleList[l].fPosType)
                                                        {
                                                            HPoint2D HPItem = new HPoint2D();
                                                            HPItem.HoleName = CU.SetItemNameByType(ItemList[i].ItemNameType);
                                                            HPItem.X = Convert.ToDecimal(Convert.ToDecimal(SHoleList[l].ItemX)
                                                                - Convert.ToDecimal(RLFList[k].plate_X0));
                                                            HPItem.X = Math.Round(HPItem.X, 2);
                                                            HPItem.Y = Convert.ToDecimal(SHoleList[l].ItemY);
                                                            HPItem.Y = Math.Round(HPItem.Y, 2);
                                                            HPItem.Z0 = 0;
                                                            HPItem.Z1 = Convert.ToDecimal(RLFList[k].W);
                                                            HDItem.HPointList.Add(HPItem);
                                                        }
                                                    }
                                                    CHoleMouldList[FMouldIndex].HoleDataList.Add(HDItem);
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        //通孔
                                        HoleData TDItem = ATypeBuildScrewHoleByItem(ItemList[i], HoleProcessType.ThroughHole);
                                        TDItem.LineNo = ItemList[i].lineNo;
                                        int BIndex = CHoleMouldList.FindIndex(item => item.Plate_Sur.Equals("反面")
                                        && item.BoardUID.Equals(TempDimPBList[j].BoardUID));
                                        if (BIndex != -1)
                                        {
                                            List<StandardHoleData> SHoleList = ItemList[i].HSplitInfo.SplitInfoList;
                                            for (int k = 0; k < SHoleList.Count; k++)
                                            {
                                                HPoint2D HPItem = new HPoint2D();
                                                HPItem.HoleName = CU.SetItemNameByType(ItemList[i].ItemNameType);
                                                HPItem.X = Convert.ToDecimal(SHoleList[k].ItemX);
                                                HPItem.X = Math.Round(HPItem.X, 2);
                                                HPItem.Y = Convert.ToDecimal(SHoleList[k].ItemY);
                                                HPItem.Y = Math.Round(HPItem.Y, 2);
                                                HPItem.Z0 = 0;
                                                HPItem.Z1 = Convert.ToDecimal(TempDimPBList[j].PlateThick);
                                                TDItem.HPointList.Add(HPItem);
                                            }
                                            CHoleMouldList[BIndex].HoleDataList.Add(TDItem);
                                        }
                                    }
                                }
                            }

                        }

                        //处理非螺丝 拉杆/导柱/回针
                        else
                        if (JudgeNoScrewButAboutItem(ItemList[i].ItemNameType))
                        {
                            if (JudgeIsGPOrRPItem(ItemList[i].ItemNameType))
                                PrItem.Length = ItemList[i].TheoryH;
                            else
                                PrItem.Length = ItemList[i].RealH;
                            PrItem.Dim = ItemList[i].Dim;
                            if (ItemList[i].ItemNum != null)
                                PrItem.Num = (int)ItemList[i].ItemNum;

                            //处理零件通孔
                            List<BoardSectionItem> ItemTHoleBList = ItemList[i].ItemDimThroughHBList;
                            if (ItemTHoleBList.Count > 0)
                            {
                                string PlateSur = null;
                                BoardSectionItem TDBoard = ItemList[i].TDBoard;
                                InBoardPosType TDType = ItemList[i].TDPosType;
                                UnloadMoldPosType TDunloadPostType = UnloadMoldPosType.NONE;
                                if (TDBoard.BoardUID != null)
                                    TDunloadPostType = TDBoard.withaBoardPosType;

                                if (TDType == InBoardPosType.BoardUp)
                                {
                                    if (TDunloadPostType == UnloadMoldPosType.aBoardUp)
                                        PlateSur = "反面";
                                    if (TDunloadPostType == UnloadMoldPosType.aBoardDown)
                                        PlateSur = "正面";
                                }
                                if (TDType == InBoardPosType.BoardDown)
                                {
                                    if (TDunloadPostType == UnloadMoldPosType.aBoardUp)
                                        PlateSur = "正面";
                                    if (TDunloadPostType == UnloadMoldPosType.aBoardDown)
                                        PlateSur = "反面";
                                }

                                for (int z = 0; z < ItemTHoleBList.Count; z++)
                                {
                                    if (ItemTHoleBList[z].BoardCode.Equals("fangtie"))
                                    {
                                        //RL方铁都+
                                        List<HoleMould> RLFList = CHoleMouldList.FindAll(item => item.Plate_Sur.Equals(PlateSur)
                                        && item.BoardCode.Equals("fangtie"));
                                        if (RLFList.Count > 0)
                                        {
                                            for (int j = 0; j < RLFList.Count; j++)
                                            {
                                                //通孔
                                                HoleData HDItem = ATypeBuildScrewHoleByItem(ItemList[i], HoleProcessType.ThroughHole);
                                                HDItem.LineNo = ItemList[i].lineNo;
                                                List<StandardHoleData> SHoleList = ItemList[i].HSplitInfo.SplitInfoList;
                                                for (int k = 0; k < SHoleList.Count; k++)
                                                {
                                                    if (RLFList[j].fPosType == SHoleList[k].fPosType)
                                                    {
                                                        HPoint2D HPItem = new HPoint2D();
                                                        HPItem.HoleName = CU.SetItemNameByType(ItemList[i].ItemNameType);
                                                        HPItem.X = Convert.ToDecimal(Convert.ToDecimal(SHoleList[k].ItemX)
                                                            - Convert.ToDecimal(RLFList[j].plate_X0));
                                                        HPItem.X = Math.Round(HPItem.X, 2);
                                                        HPItem.Y = Convert.ToDecimal(SHoleList[k].ItemY);
                                                        HPItem.Y = Math.Round(HPItem.Y, 2);
                                                        HPItem.Z0 = 0;
                                                        HPItem.Z1 = Convert.ToDecimal(TDBoard.PlateThick);
                                                        HDItem.HPointList.Add(HPItem);
                                                    }
                                                }
                                                int FMouldIndex = CHoleMouldList.FindIndex(item => item.BoardUID.Equals(RLFList[j].BoardUID));
                                                if (FMouldIndex != -1)
                                                    CHoleMouldList[FMouldIndex].HoleDataList.Add(HDItem);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        //通孔
                                        HoleData TDItem = ATypeBuildScrewHoleByItem(ItemList[i], HoleProcessType.ThroughHole);
                                        TDItem.LineNo = ItemList[i].lineNo;
                                        int BIndex = CHoleMouldList.FindIndex(item => item.Plate_Sur.Equals("反面")
                                        && item.BoardUID.Equals(ItemTHoleBList[z].BoardUID));
                                        if (BIndex != -1)
                                        {
                                            List<StandardHoleData> SHoleList = ItemList[i].HSplitInfo.SplitInfoList;
                                            for (int k = 0; k < SHoleList.Count; k++)
                                            {
                                                HPoint2D HPItem = new HPoint2D();
                                                HPItem.HoleName = CU.SetItemNameByType(ItemList[i].ItemNameType);
                                                HPItem.X = Convert.ToDecimal(SHoleList[k].ItemX);
                                                HPItem.X = Math.Round(HPItem.X, 2);
                                                HPItem.Y = Convert.ToDecimal(SHoleList[k].ItemY);
                                                HPItem.Y = Math.Round(HPItem.Y, 2);
                                                HPItem.Z0 = 0;
                                                HPItem.Z1 = Convert.ToDecimal(ItemTHoleBList[z].PlateThick);
                                                TDItem.HPointList.Add(HPItem);
                                            }
                                            CHoleMouldList[BIndex].HoleDataList.Add(TDItem);
                                        }
                                    }
                                }
                            }

                            //处理零件沉头孔
                            if (ItemList[i].TDPosType != InBoardPosType.NONE)
                            {
                                string PlateSur = null;
                                BoardSectionItem TDBoard = ItemList[i].TDBoard;
                                if (TDBoard.BoardUID != null)
                                {
                                    InBoardPosType TDType = ItemList[i].TDPosType;
                                    UnloadMoldPosType TDunloadPostType = UnloadMoldPosType.NONE;
                                    if (TDBoard.BoardUID != null)
                                        TDunloadPostType = TDBoard.withaBoardPosType;

                                    if (TDType == InBoardPosType.BoardUp)
                                    {
                                        if (TDunloadPostType == UnloadMoldPosType.aBoardUp)
                                            PlateSur = "反面";
                                        if (TDunloadPostType == UnloadMoldPosType.aBoardDown)
                                            PlateSur = "正面";
                                    }
                                    if (TDType == InBoardPosType.BoardDown)
                                    {
                                        if (TDunloadPostType == UnloadMoldPosType.aBoardUp)
                                            PlateSur = "正面";
                                        if (TDunloadPostType == UnloadMoldPosType.aBoardDown)
                                            PlateSur = "反面";
                                    }
                                    if (TDBoard.BoardCode.Equals("fangtie"))
                                    {
                                        //RL方铁都+
                                        List<HoleMould> RLFList = CHoleMouldList.FindAll(item => item.Plate_Sur.Equals("反面")
                                        && item.BoardCode.Equals("fangtie"));
                                        if (RLFList.Count > 0)
                                        {
                                            for (int j = 0; j < RLFList.Count; j++)
                                            {
                                                HoleData HDItem = ATypeBuildScrewHoleByItem(ItemList[i], HoleProcessType.Sinkhead);
                                                HDItem.LineNo = ItemList[i].lineNo;
                                                List<StandardHoleData> SHoleList = ItemList[i].HSplitInfo.SplitInfoList;
                                                for (int k = 0; k < SHoleList.Count; k++)
                                                {
                                                    if (RLFList[j].fPosType == SHoleList[k].fPosType)
                                                    {
                                                        HPoint2D HPItem = new HPoint2D();
                                                        HPItem.HoleName = CU.SetItemNameByType(ItemList[i].ItemNameType);
                                                        HPItem.X = Convert.ToDecimal(Convert.ToDecimal(SHoleList[k].ItemX)
                                                            - Convert.ToDecimal(RLFList[j].plate_X0));
                                                        HPItem.X = Math.Round(HPItem.X, 2);
                                                        HPItem.Y = Convert.ToDecimal(SHoleList[k].ItemY);
                                                        HPItem.Y = Math.Round(HPItem.Y, 2);
                                                        HPItem.Z0 = 0;
                                                        HPItem.Z1 = Convert.ToDecimal(TDBoard.PlateThick);
                                                        HDItem.HPointList.Add(HPItem);
                                                    }
                                                }
                                                int FMouldIndex = CHoleMouldList.FindIndex(item => item.BoardUID.Equals(RLFList[j].BoardUID));
                                                if (FMouldIndex != -1)
                                                    CHoleMouldList[FMouldIndex].HoleDataList.Add(HDItem);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        HoleData TDItem = ATypeBuildScrewHoleByItem(ItemList[i], HoleProcessType.Sinkhead);
                                        TDItem.LineNo = ItemList[i].lineNo;
                                        int TDIndex = CHoleMouldList.FindIndex(item => item.Plate_Sur.Equals(PlateSur)
                                        && item.BoardUID.Equals(TDBoard.BoardUID));
                                        if (TDIndex != -1)
                                        {
                                            List<StandardHoleData> SHoleList = ItemList[i].HSplitInfo.SplitInfoList;
                                            for (int k = 0; k < SHoleList.Count; k++)
                                            {
                                                HPoint2D HPItem = new HPoint2D();
                                                HPItem.HoleName = CU.SetItemNameByType(ItemList[i].ItemNameType);
                                                HPItem.X = Convert.ToDecimal(SHoleList[k].ItemX);
                                                HPItem.X = Math.Round(HPItem.X, 2);
                                                HPItem.Y = Convert.ToDecimal(SHoleList[k].ItemY);
                                                HPItem.Y = Math.Round(HPItem.Y, 2);
                                                HPItem.Z0 = 0;
                                                HPItem.Z1 = Convert.ToDecimal(TDBoard.PlateThick);
                                                TDItem.HPointList.Add(HPItem);
                                            }
                                            CHoleMouldList[TDIndex].HoleDataList.Add(TDItem);
                                        }
                                    }
                                }
                            }

                            //处理避空信息
                            List<ItemBKInfo> BKList = ItemList[i].ItemBKInfoList;
                            if (BKList.Count > 0)
                            {
                                for (int bki = 0; bki < BKList.Count; bki++)
                                {
                                    List<DeadReckBKTempInfo> boardBKList = BKList[bki].DetailInfoList;
                                    if (boardBKList.Count > 0)
                                    {
                                        for (int di = 0; di < boardBKList.Count; di++)
                                        {
                                            DeadReckBKTempInfo tempdInfo = boardBKList[di];
                                            InBoardType bkBType = tempdInfo.BKInBoardType;
                                            string targetBKBUID = tempdInfo.BKInBoardUID;
                                            BoardSectionItem targetBKBoard = AssemblyShareData.ASectionList.Find(item => item.BoardUID.Equals(targetBKBUID));
                                            if(targetBKBoard != null)
                                            {
                                                //通孔 全部 默认反面
                                                if (bkBType == InBoardType.Through)
                                                {
                                                    if (targetBKBUID.Contains("fangtie"))
                                                    {
                                                        List<HoleMould> RLFList = CHoleMouldList.FindAll(item => item.Plate_Sur.Equals("反面")
                                                        && item.BoardCode.Equals("fangtie"));
                                                        if (RLFList.Count > 0)
                                                        {
                                                            for (int k = 0; k < RLFList.Count; k++)
                                                            {
                                                                Boolean LF = RLFList[k].fPosType == FPosType.L;
                                                                Boolean RF = RLFList[k].fPosType == FPosType.R;
                                                                HoleData BKItem = ATypeBuildScrewHoleByItem(ItemList[i], HoleProcessType.BK_Hole);
                                                                BKItem.LineNo = ItemList[i].lineNo;
                                                                int FMouldIndex = CHoleMouldList.FindIndex(item => item.BoardUID.Equals(RLFList[k].BoardUID));
                                                                if (FMouldIndex != -1)
                                                                {
                                                                    List<StandardHoleData> BKHoleList = ItemList[i].HSplitInfo.SplitInfoList;
                                                                    for (int bk = 0; bk < BKHoleList.Count; bk++)
                                                                    {
                                                                        Boolean BKLF = BKHoleList[bk].fPosType == FPosType.L;
                                                                        Boolean BKRF = BKHoleList[bk].fPosType == FPosType.R;
                                                                        if (BKLF && LF)
                                                                        {
                                                                            HPoint2D HPItem = new HPoint2D();
                                                                            HPItem.HoleName = CU.SetItemNameByType(ItemList[i].ItemNameType);
                                                                            HPItem.X = Convert.ToDecimal(Convert.ToDecimal(BKHoleList[k].ItemX)
                                                                                - Convert.ToDecimal(RLFList[k].plate_X0));
                                                                            HPItem.X = Math.Round(HPItem.X, 2);
                                                                            HPItem.Y = Convert.ToDecimal(BKHoleList[bk].ItemY);
                                                                            HPItem.Y = Math.Round(HPItem.Y, 2);
                                                                            HPItem.Z0 = 0;
                                                                            HPItem.Z1 = Convert.ToDecimal(targetBKBoard.PlateThick);
                                                                            BKItem.HPointList.Add(HPItem);
                                                                        }
                                                                        if (BKRF && RF)
                                                                        {
                                                                            HPoint2D HPItem = new HPoint2D();
                                                                            HPItem.HoleName = CU.SetItemNameByType(ItemList[i].ItemNameType);
                                                                            HPItem.X = Convert.ToDecimal(Convert.ToDecimal(BKHoleList[k].ItemX)
                                                                                - Convert.ToDecimal(RLFList[k].plate_X0));
                                                                            HPItem.X = Math.Round(HPItem.X, 2);
                                                                            HPItem.Y = Convert.ToDecimal(BKHoleList[bk].ItemY);
                                                                            HPItem.Y = Math.Round(HPItem.Y, 2);
                                                                            HPItem.Z0 = 0;
                                                                            HPItem.Z1 = Convert.ToDecimal(targetBKBoard.PlateThick);
                                                                            BKItem.HPointList.Add(HPItem);
                                                                        }
                                                                        
                                                                    }
                                                                    CHoleMouldList[FMouldIndex].HoleDataList.Add(BKItem);
                                                                }
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        int TDIndex = CHoleMouldList.FindIndex(item => item.Plate_Sur.Equals("反面")
                                                        && item.BoardUID.Equals(tempdInfo.BKInBoardUID));
                                                        HoleData TDItem = ATypeBuildScrewHoleByItem(ItemList[i], HoleProcessType.BK_Hole);
                                                        TDItem.LineNo = ItemList[i].lineNo;
                                                        if (TDIndex != -1)
                                                        {
                                                            List<StandardHoleData> SHoleList = ItemList[i].HSplitInfo.SplitInfoList;
                                                            for (int k = 0; k < SHoleList.Count; k++)
                                                            {
                                                                HPoint2D HPItem = new HPoint2D();
                                                                HPItem.HoleName = CU.SetItemNameByType(ItemList[i].ItemNameType);
                                                                HPItem.X = Convert.ToDecimal(SHoleList[k].ItemX);
                                                                HPItem.X = Math.Round(HPItem.X, 2);
                                                                HPItem.Y = Convert.ToDecimal(SHoleList[k].ItemY);
                                                                HPItem.Y = Math.Round(HPItem.Y, 2);
                                                                HPItem.Z0 = 0;
                                                                HPItem.Z1 = Convert.ToDecimal(targetBKBoard.PlateThick);
                                                                TDItem.HPointList.Add(HPItem);
                                                            }
                                                            CHoleMouldList[TDIndex].HoleDataList.Add(TDItem);
                                                        }
                                                    }
                                                }
                                                //盲孔
                                                else
                                                {
                                                    string Plate_Sur = "";
                                                    UnloadMoldPosType bkPosType = targetBKBoard.withaBoardPosType;
                                                    if (bkBType == InBoardType.Up)
                                                    {
                                                        if (bkPosType == UnloadMoldPosType.aBoardUp)
                                                            Plate_Sur = "反面";
                                                        if (bkPosType == UnloadMoldPosType.aBoardDown)
                                                            Plate_Sur = "正面";
                                                    }
                                                    if (bkBType == InBoardType.Down)
                                                    {
                                                        if (bkPosType == UnloadMoldPosType.aBoardUp)
                                                            Plate_Sur = "正面";
                                                        if (bkPosType == UnloadMoldPosType.aBoardDown)
                                                            Plate_Sur = "反面";
                                                    }
                                                    if (targetBKBUID.Contains("fangtie"))
                                                    {
                                                        List<HoleMould> RLFList = CHoleMouldList.FindAll(item => item.Plate_Sur.Equals(Plate_Sur)
                                                        && item.BoardCode.Equals("fangtie"));
                                                        if (RLFList.Count > 0)
                                                        {
                                                            for (int j = 0; j < RLFList.Count; j++)
                                                            {
                                                                HoleData BKItem = ATypeBuildScrewHoleByItem(ItemList[i], HoleProcessType.BKBlind);
                                                                BKItem.LineNo = ItemList[i].lineNo;
                                                                List<StandardHoleData> SHoleList = ItemList[i].HSplitInfo.SplitInfoList;
                                                                for (int k = 0; k < SHoleList.Count; k++)
                                                                {
                                                                    if (RLFList[j].fPosType == SHoleList[k].fPosType)
                                                                    {
                                                                        HPoint2D HPItem = new HPoint2D();
                                                                        HPItem.HoleName = CU.SetItemNameByType(ItemList[i].ItemNameType);
                                                                        HPItem.X = Convert.ToDecimal(Convert.ToDecimal(SHoleList[k].ItemX)
                                                                            - Convert.ToDecimal(RLFList[j].plate_X0));
                                                                        HPItem.X = Math.Round(HPItem.X, 2);
                                                                        HPItem.Y = Convert.ToDecimal(SHoleList[k].ItemY);
                                                                        HPItem.Y = Math.Round(HPItem.Y, 2);
                                                                        HPItem.Z0 = 0;
                                                                        HPItem.Z1 = Convert.ToDecimal(tempdInfo.H);
                                                                        BKItem.HPointList.Add(HPItem);
                                                                    }
                                                                }
                                                                int FMouldIndex = CHoleMouldList.FindIndex(item => item.BoardUID.Equals(RLFList[j].BoardUID));
                                                                if (FMouldIndex != -1)
                                                                    CHoleMouldList[FMouldIndex].HoleDataList.Add(BKItem);
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        int TDIndex = CHoleMouldList.FindIndex(item => item.Plate_Sur.Equals(Plate_Sur)
                                                        && item.BoardUID.Equals(targetBKBUID));
                                                        HoleData TDItem = ATypeBuildScrewHoleByItem(ItemList[i], HoleProcessType.BKBlind);
                                                        TDItem.LineNo = ItemList[i].lineNo;
                                                        if (TDIndex != -1)
                                                        {
                                                            List<StandardHoleData> SHoleList = ItemList[i].HSplitInfo.SplitInfoList;
                                                            for (int k = 0; k < SHoleList.Count; k++)
                                                            {
                                                                HPoint2D HPItem = new HPoint2D();
                                                                HPItem.HoleName = CU.SetItemNameByType(ItemList[i].ItemNameType);
                                                                HPItem.X = Convert.ToDecimal(SHoleList[k].ItemX);
                                                                HPItem.X = Math.Round(HPItem.X, 2);
                                                                HPItem.Y = Convert.ToDecimal(SHoleList[k].ItemY);
                                                                HPItem.Y = Math.Round(HPItem.Y, 2);
                                                                HPItem.Z0 = 0;
                                                                HPItem.Z1 = Convert.ToDecimal(tempdInfo.H);
                                                                TDItem.HPointList.Add(HPItem);
                                                            }
                                                            CHoleMouldList[TDIndex].HoleDataList.Add(TDItem);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        //处理导套
                        else
                        if (JudgeItemTypeAboutBush(ItemList[i].ItemNameType))
                        {
                            Boolean BBF = ItemList[i].ItemCode.Contains("BBush");
                            PrItem.Length = ItemList[i].RealH;
                            PrItem.Dim = ItemList[i].Dim;
                            if (ItemList[i].ItemNum != null)
                                PrItem.Num = (int)ItemList[i].ItemNum;
                            //处理导套外径板相关
                            List<BoardSectionItem> BushSizeList = ItemList[i].BushBoardList;
                            //1.默认反面
                            //2.推板同上: but if推板出现回针螺丝 推板的A套默认正面
                            Boolean RPScrewF = ItemList.FindIndex(item => item.ItemNameType == DItemNameType.ReturnPinScrew) != -1;
                            if (BushSizeList.Count > 0)
                            {
                                for (int z = 0; z < BushSizeList.Count; z++)
                                {
                                    string PlateSur = "反面";
                                    Boolean InStBF = BushSizeList[z].BoardCode.Equals("stBoard");
                                    if (RPScrewF && InStBF)
                                        PlateSur = "正面";
                                    //默认设置为通孔
                                    if (BushSizeList[z].BoardCode.Equals("fangtie"))
                                    {
                                        //RL方铁都+
                                        List<HoleMould> RLFList = CHoleMouldList.FindAll(item => item.Plate_Sur.Equals(PlateSur)
                                        && item.BoardCode.Equals("fangtie"));
                                        if (RLFList.Count > 0)
                                        {
                                            for (int j = 0; j < RLFList.Count; j++)
                                            {
                                                HoleProcessType PType = HoleProcessType.None;
                                                if (ItemList[i].ItemNameType.ToString().Contains("ABush"))
                                                    PType = HoleProcessType.FlatFineBH;
                                                HoleData HDItem = ATypeBuildScrewHoleByItem(ItemList[i], PType);
                                                HDItem.LineNo = ItemList[i].lineNo;
                                                List<StandardHoleData> SHoleList = ItemList[i].HSplitInfo.SplitInfoList;
                                                for (int k = 0; k < SHoleList.Count; k++)
                                                {
                                                    if (RLFList[j].fPosType == SHoleList[k].fPosType)
                                                    {
                                                        HPoint2D HPItem = new HPoint2D();
                                                        HPItem.HoleName = CU.SetItemNameByType(ItemList[i].ItemNameType);
                                                        HPItem.X = Convert.ToDecimal(Convert.ToDecimal(SHoleList[k].ItemX)
                                                            - Convert.ToDecimal(RLFList[j].plate_X0));
                                                        HPItem.X = Math.Round(HPItem.X, 2);
                                                        HPItem.Y = Convert.ToDecimal(SHoleList[k].ItemY);
                                                        HPItem.Y = Math.Round(HPItem.Y, 2);
                                                        HPItem.Z0 = 0;
                                                        HPItem.Z1 = Convert.ToDecimal(BushSizeList[z].PlateThick);
                                                        HDItem.HPointList.Add(HPItem);
                                                    }
                                                }
                                                int FMouldIndex = CHoleMouldList.FindIndex(item => item.BoardUID.Equals(RLFList[j].BoardUID));
                                                if (FMouldIndex != -1)
                                                    CHoleMouldList[FMouldIndex].HoleDataList.Add(HDItem);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        HoleProcessType PType = HoleProcessType.None;
                                        if (ItemList[i].ItemNameType.ToString().Contains("ABush"))
                                            PType = HoleProcessType.FlatFineBH;
                                        HoleData TDItem = ATypeBuildScrewHoleByItem(ItemList[i], PType);
                                        TDItem.LineNo = ItemList[i].lineNo;
                                        int TDIndex = CHoleMouldList.FindIndex(item => item.Plate_Sur.Equals(PlateSur)
                                        && item.BoardUID.Equals(BushSizeList[z].BoardUID));
                                        if (TDIndex != -1)
                                        {
                                            List<StandardHoleData> SHoleList = ItemList[i].HSplitInfo.SplitInfoList;
                                            for (int k = 0; k < SHoleList.Count; k++)
                                            {
                                                HPoint2D HPItem = new HPoint2D();
                                                HPItem.HoleName = CU.SetItemNameByType(ItemList[i].ItemNameType);
                                                HPItem.X = Convert.ToDecimal(SHoleList[k].ItemX);
                                                HPItem.X = Math.Round(HPItem.X, 2);
                                                HPItem.Y = Convert.ToDecimal(SHoleList[k].ItemY);
                                                HPItem.Y = Math.Round(HPItem.Y, 2);
                                                HPItem.Z0 = 0;
                                                HPItem.Z1 = Convert.ToDecimal(BushSizeList[z].PlateThick);
                                                TDItem.HPointList.Add(HPItem);
                                            }
                                            CHoleMouldList[TDIndex].HoleDataList.Add(TDItem);
                                        }
                                    }

                                }
                            }

                            //B套 沉头
                            if (BBF)
                            {
                                HoleData TDItem = ATypeBuildScrewHoleByItem(ItemList[i], HoleProcessType.Sinkhead);
                                TDItem.LineNo = ItemList[i].lineNo;
                                string PlateSur = "反面";
                                Boolean judgeBushTDF = ItemList[i].BushTDPosType != InBoardPosType.NONE;
                                if (judgeBushTDF)
                                {
                                    BoardSectionItem BushTDBoard = ItemList[i].BushTDBoard;
                                    if (BushTDBoard.BoardUID != null)
                                    {
                                        Boolean upF = BushTDBoard.withaBoardPosType == UnloadMoldPosType.aBoardUp;
                                        Boolean bushTDPosF = ItemList[i].BushTDPosType == InBoardPosType.BoardUp;

                                        if (upF)
                                        {
                                            if (bushTDPosF)
                                                PlateSur = "反面";
                                            else
                                                PlateSur = "正面";
                                        }
                                        else
                                        {
                                            if (bushTDPosF)
                                                PlateSur = "正面";
                                            else
                                                PlateSur = "反面";
                                        }

                                        int bushTDIndex = CHoleMouldList.FindIndex(item => item.Plate_Sur.Equals(PlateSur)
                                        && item.BoardUID.Equals(BushTDBoard.BoardUID));
                                        if (bushTDIndex != -1)
                                        {
                                            List<StandardHoleData> SHoleList = ItemList[i].HSplitInfo.SplitInfoList;
                                            for (int k = 0; k < SHoleList.Count; k++)
                                            {
                                                HPoint2D HPItem = new HPoint2D();
                                                HPItem.HoleName = CU.SetItemNameByType(ItemList[i].ItemNameType);
                                                HPItem.X = Convert.ToDecimal(SHoleList[k].ItemX);
                                                HPItem.X = Math.Round(HPItem.X, 2);
                                                HPItem.Y = Convert.ToDecimal(SHoleList[k].ItemY);
                                                HPItem.Y = Math.Round(HPItem.Y, 2);
                                                HPItem.Z0 = 0;
                                                HPItem.Z1 = Convert.ToDecimal(BushTDBoard.PlateThick);
                                                TDItem.HPointList.Add(HPItem);
                                            }
                                            CHoleMouldList[bushTDIndex].HoleDataList.Add(TDItem);
                                        }
                                    }
                                }

                            }

                        }

                        PrItemList.Add(PrItem);
                    }
                }

                //界面UI 手动补的零件
                List<LabourSingleItem> LabourItemList = ShareItemData.UISurplusItemList;
                if (LabourItemList.Count > 0)
                {
                    for (int li = 0; li < LabourItemList.Count; li++)
                    {
                        ItemBaseParamData LItem = new ItemBaseParamData();
                        LItem.ItemName = LabourItemList[li].ItemName;
                        LItem.ItemType = (int)LabourItemList[li].ItemNameType;
                        LItem.Remark = LabourItemList[li].UIRemark;
                        LItem.SortNo = CU.SetSortByItemNameType(LabourItemList[li].ItemNameType);
                        //螺丝给理论
                        LItem.Length = LabourItemList[li].ItemL;
                        LItem.Dim = LabourItemList[li].ItemDim;
                        if (LabourItemList[li].ItemNum != 0)
                            LItem.Num = LabourItemList[li].ItemNum;
                        PrItemList.Add(LItem);
                    }
                }

                //需要上传的零件可能出现相同规格 需要手动合并一次
                if (PrItemList.Count > 0)
                {
                    Dictionary<int, List<ItemBaseParamData>> Dic = new Dictionary<int, List<ItemBaseParamData>>();
                    for (int i = 0; i < PrItemList.Count; i++)
                    {
                        if (Dic.ContainsKey(PrItemList[i].ItemType))
                        {
                            ItemBaseParamData DicItem = Dic[PrItemList[i].ItemType].First();
                            if (JudgeItemSameSpecification(DicItem, PrItemList[i]))
                            {
                                int ToAddNum = PrItemList[i].Num;
                                Dic[PrItemList[i].ItemType].First().Num += ToAddNum;
                            }
                            else
                                Dic[PrItemList[i].ItemType].Add(PrItemList[i]);
                        }
                        else
                            Dic.Add(PrItemList[i].ItemType, new List<ItemBaseParamData>() { PrItemList[i] });
                    }
                    List<int> DicKeys = Dic.Keys.ToList();
                    if (DicKeys.Count > 0)
                    {
                        List<ItemBaseParamData> TargetList = new List<ItemBaseParamData>();
                        DicKeys.ForEach(key => TargetList.AddRange(Dic[key]));
                        if (TargetList.Count > 0)
                            PrItemList = TargetList;
                    }
                }
                if (PrItemList.Count > 0)
                {
                    PrItemList = PrItemList.OrderBy(item => item.SortNo).ToList();
                    for (int i = 0; i < PrItemList.Count; i++)
                        PrItemList[i].SortNo = i + 1;
                }

                //合并相同宽度的方铁
                if (PBoardList.Count > 0)
                {
                    List<ProcessBoard> FangtiePBList = PBoardList.FindAll(item => item.BoardCode.Equals("fangtie")).ToList();
                    if (FangtiePBList.Count > 0)
                    {
                        List<ProcessBoard> tempFPBList = new List<ProcessBoard>();
                        PBoardList.RemoveAll(item => item.BoardCode.Equals("fangtie"));
                        for (int fi = 0; fi < FangtiePBList.Count; fi++)
                        {
                            int tempIndex = tempFPBList.FindIndex(item => item.Width == FangtiePBList[fi].Width);
                            if (tempIndex == -1)
                                tempFPBList.Add(FangtiePBList[fi]);
                            else
                                tempFPBList[tempIndex].Qty += 1;
                        }
                        PBoardList.AddRange(tempFPBList);
                    }
                }

                if (PBoardList.Count > 0)
                {
                    PBoardList = PBoardList.OrderBy(item => item.Seq_no).ToList();
                    for (int i = 0; i < PBoardList.Count; i++)
                    {
                        PBoardList[i].Seq_no = i + 1;
                        //将LRC方铁 名称设置为 -> 方铁
                        if (PBoardList[i].Plate_Name.Contains("方铁"))
                            PBoardList[i].Plate_Name = "方铁";
                    }
                }

                //上送DB的加工项目
                CHoleMouldList = CHoleMouldList.FindAll(item => item.HoleDataList.Count > 0);

                ResData.BoardData = PBoardList;
                ResData.ItemData = PrItemList;
                ResData.FrameData = FrameList;
                ResData.processDetailListInfo = GetERPProcessDetailListInfo();
                ResData.ERPProcessData = GetERPProcessInfo();
                ResData.HoleProcessData = CHoleMouldList;
            }
            catch (System.Exception ex)
            {
                string errorMsg = ex.Message;
                CUException error = new CUException(ErrorType.ATypeTranCoorError);
                MessageBox.Show(error.ErrorTig());
            }
            return ResData;
        }

        //单独提取ERP关注的加工项目
        public static List<EGPProcessinfo> GetERPProcessInfo()
        {
            List<EGPProcessinfo> resList = new List<EGPProcessinfo>();
            List<SingleItem> ItemList = ShareItemData.UIItemList;
            List<LabourSingleItem> LabourItemList = ShareItemData.UISurplusItemList;
            SingleItem egpItem = ItemList.Find(Item => Item.ItemNameType == DItemNameType.EGPBush);
            if (egpItem != null)
            {
                EGPProcessinfo tempItem = new EGPProcessinfo();
                tempItem.processName = "中托司";
                tempItem.length = egpItem.RealH;
                tempItem.dim = egpItem.Dim;
                tempItem.num = (int)egpItem.ItemNum;
                tempItem.holeL = null;
                tempItem.holeW = null;
                resList.Add(tempItem);
            }
            else
            {
                LabourSingleItem labourEGPItem = LabourItemList.Find(Item => Item.ItemNameType == DItemNameType.EGPBush);
                if (labourEGPItem != null)
                {
                    EGPProcessinfo tempItem = new EGPProcessinfo();
                    tempItem.processName = "中托司";
                    tempItem.length = (int)labourEGPItem.ItemL;
                    tempItem.dim = labourEGPItem.ItemDim;
                    tempItem.num = (int)labourEGPItem.ItemNum;
                    tempItem.holeL = null;
                    tempItem.holeW = null;
                    resList.Add(tempItem);
                }
            }
            return resList;
        }

        public static ProcessDetailListInfo GetERPProcessDetailListInfo()
        {
            ProcessDetailListInfo Res = new ProcessDetailListInfo();
            Res.egpProcessinfo = AssemblyShareData.egpProcessinfo;
            Res.koHoleProcessinfo = AssemblyShareData.koHoleProcessinfo;
            Res.sHoleProcessInfo = AssemblyShareData.sHoleProcessInfo;
            return Res;
        }

        //自动模式 将加工孔数据保存至数据库
        public static void ATypeSaveProcessHoleToDB(string tempOrder, string UploadUser, DateTime uploadtime, List<HoleMould> ProcessHoleList)
        {
            string SQLServerAddr = "139.159.178.26";
            string UID = "CAM";
            string PWD = "CAM";
            string SQLConnectionString = $"Server={SQLServerAddr};Database=DXMG;UID={UID};PWD={PWD}";
            if (ProcessHoleList.Count > 0)
            {
                try
                {
                    using (SqlConnection conn = new SqlConnection(SQLConnectionString))
                    {
                        try { conn.Open(); }
                        catch (System.Exception)
                        {
                            throw new CUException(ErrorType.DBConnectionError);
                        }
                        string tostr = $"INSERT INTO [DXMG].[dbo].[R2D_Temp_Order] (order_number) " +
                                                                            $"values ('{tempOrder}');" +
                                                                                   $"SELECT SCOPE_IDENTITY()";
                        SqlCommand reado = new SqlCommand(tostr, conn);
                        reado.ExecuteScalar();
                        for (int i = 0; i < ProcessHoleList.Count; i++)
                        {
                            string bcmdstr = $"INSERT INTO [DXMG].[dbo].[HOLE_mould] (Cut, order_number, L, W, H, Bat, Plate_Sur, Plate_Base,plate_X0,plate_Y0,plate_Z0, Create_By, Create_Time," +
                                $" plate_name, plate_Attribute, systemid, version, plate_lineno) " +
                                $"values ('3', '{tempOrder}', '{ProcessHoleList[i].L}', '{ProcessHoleList[i].W}', '{ProcessHoleList[i].H}'," +
                                $"'{ProcessHoleList[i].Bat}', '{ProcessHoleList[i].Plate_Sur}', '{ProcessHoleList[i].Plate_Base}', " +
                                $"'{ProcessHoleList[i].plate_X0}', '{ProcessHoleList[i].plate_Y0}', '{ProcessHoleList[i].plate_Z0}', '{UploadUser}', '{uploadtime:G}', '{ProcessHoleList[i].plate_name}','{ProcessHoleList[i].plate_Attribute}','4','1','{ProcessHoleList[i].plate_LineNo}');" +
                                $"SELECT SCOPE_IDENTITY()";
                            SqlCommand readboard = new SqlCommand(bcmdstr, conn);
                            int? newMouldId = Convert.ToInt32(readboard.ExecuteScalar());
                            if (newMouldId != null)
                            {
                                List<HoleData> HDList = ProcessHoleList[i].HoleDataList;
                                for (int j = 0; j < HDList.Count; j++)
                                {
                                    string holecmdstr = $"insert into [DXMG].[dbo].[HOLE_data] (Hole_Name,Line_No, D, D_J, M_Type, Rc_YesNo, TH, TD, L, W, Quantity, Create_By, Create_Time, Hole_id, process_Type)" +
                                                        $"values ('{HDList[j].Hole_Name}', '{HDList[j].LineNo}', '{HDList[j].D}', '1', '{HDList[j].M_Type}', " +
                                                        $"{HDList[j].Rc_YesNo}, {HDList[j].TH}, {HDList[j].TD}, '{HDList[j].L}', '{HDList[j].W}', '{HDList[j].Quantity}', " +
                                                        $"'{UploadUser}', '{uploadtime:G}', '{newMouldId}', '{HDList[j].process_Type}');" +
                                                        $"SELECT SCOPE_IDENTITY()";
                                    SqlCommand readhole = new SqlCommand(holecmdstr, conn);
                                    int? newholeId = Convert.ToInt32(readhole.ExecuteScalar());
                                    if (newholeId != null)
                                    {
                                        List<HPoint2D> HPList = HDList[j].HPointList;
                                        for (int k = 0; k < HPList.Count; k++)
                                        {
                                            string pointcmdstr = $"insert into [DXMG].[dbo].[HPoint_2D] (X, Y, Z0, Z1, Create_By, Create_Time, Point_id)" +
                                                                               $"values('{HPList[k].X}', '{HPList[k].Y}', '0', '{HPList[k].Z1}'," +
                                                                               $" '{UploadUser}', '{uploadtime:G}', '{newholeId}')";
                                            SqlCommand readpoint = new SqlCommand(pointcmdstr, conn);
                                            readpoint.ExecuteScalar();
                                        }
                                    }
                                }
                            }

                        }

                        conn.Close();
                    }
                }
                catch (System.Exception ex)
                {
                    CUException error = new CUException(ErrorType.ATypeTranProcessDataError);
                    MessageBox.Show(error.ErrorTig());
                }
            }
        }


        //调用ERP记录 (错误类型 抛出的异常信息 报价详情)
        public void CallERPLog(Boolean invokeFlag, CUException error, string errorMessage, AMTypeUPloadRecordInfo RInfo)
        {
            ErrorLogInfo errorLogInfo = new ErrorLogInfo();
            errorLogInfo.TempOrderUID = RInfo.UID;
            errorLogInfo.DwgFilePath = RInfo.dwgfilePath;
            errorLogInfo.ErrorInfo = errorMessage;
            errorLogInfo.errorType = error.ErrorTig();
            errorLogInfo.ErrorCreateTime = RInfo.uploadTime;
            errorLogInfo.jobNumberName = RInfo.jobNumberName;
            errorLogInfo.jobNumber = RInfo.jobNumber;

            string SQLServerAddr = "139.159.178.26";
            string UID = "CAM";
            string PWD = "CAM";
            string SQLConnectionString = $"Server={SQLServerAddr};Database=DXMG;UID={UID};PWD={PWD}";
            try
            {
                using (SqlConnection conn = new SqlConnection(SQLConnectionString))
                {
                    try
                    {
                        conn.Open();
                    }
                    catch (System.Exception)
                    {
                        MessageBox.Show("无法连接139.159.178.26 数据库!");
                        throw;
                    }

                    string pointcmdstr = $"INSERT INTO [DXMG].[dbo].[R2D_ErrorLog] (TempOrderUID, DwgFilePath, invokeFlag,ErrorInfo, errorType, jobNumberName,ErrorCreateTime, jobNumber)" +
                                                                               $"values('{errorLogInfo.TempOrderUID}', '{errorLogInfo.DwgFilePath}','{invokeFlag}', '{errorLogInfo.ErrorInfo}', '{errorLogInfo.errorType}'," +
                                                                               $" '{errorLogInfo.jobNumberName}', '{errorLogInfo.ErrorCreateTime:G}', '{errorLogInfo.jobNumber}')";
                    SqlCommand readpoint = new SqlCommand(pointcmdstr, conn);
                    readpoint.ExecuteScalar();
                    conn.Close();
                }
            }
            catch (System.Exception)
            {
                //MessageBox.Show("加工数据入库失败!");
                //throw;
            }
        }


        //判断零件规格是否一致
        public static Boolean JudgeItemSameSpecification(ItemBaseParamData Item1, ItemBaseParamData Item2)
        {
            Boolean F1 = Item1.Length == Item2.Length;
            Boolean F2 = Item1.Dim == Item2.Dim;
            return F1 && F2;
        }

        //手动模式 序列化 原始数据副本
        public static string MTypeSerializationOriginData(MTypeAllCheckBoxVInfo BVInfo)
        {
            string Res = null;
            MTypeAllPriInfo info = new MTypeAllPriInfo();
            info.MBoardList = AssemblyShareData.MSectionList;
            info.MItemList = ShareItemData.MItemList;
            info.CBInfo = BVInfo;
            Res = JsonConvert.SerializeObject(info).ToString();
            return Res;
        }

        //手动模式 转换JSON 上传记录
        public static AMTypeUPloadRecordInfo MTypeTransToRecordInfo(ProcessData pData)
        {
            AMTypeUPloadRecordInfo info = new AMTypeUPloadRecordInfo();
            ModeBasicData basicData = pData.BasicData;
            //基础查询数据
            info.fancy = basicData.FancyType;
            info.modeSize = basicData.ModeSize;
            info.customer = basicData.Customer;
            info.batchNum = basicData.BatchNum;
            info.modeNum = basicData.ModeNum;
            info.jobNumber = basicData.JobNumber;
            return info;
        }

        //自动模式 报价数据&上传记录 TO EDIT 
        public static AMTypeUPloadRecordInfo AutoTypeTransToRecordInfo(ProcessData pData)
        {
            AMTypeUPloadRecordInfo info = new AMTypeUPloadRecordInfo();
            AMTypeRQuoInfo quoInfo = new AMTypeRQuoInfo();
            ModeBasicData basicData = pData.BasicData;
            //基础查询数据
            info.fancy = basicData.FancyType;
            info.modeSize = basicData.ModeSize;
            info.customer = basicData.Customer;
            info.batchNum = basicData.BatchNum;
            info.modeNum = basicData.ModeNum;
            info.jobNumber = basicData.JobNumber;
            quoInfo.BoardList = AssemblyShareData.AUIBlueSectionList;
            //直接保存零件全量信息 序列化会引发ZWCAD BUG 转换一下
            List<SingleItem> UIItemList = ShareItemData.UIItemList;
            if (UIItemList.Count > 0)
            {
                for (int i = 0; i < UIItemList.Count; i++)
                {
                    LabourSingleItem LItem = new LabourSingleItem();
                    LItem.ItemCode = UIItemList[i].ItemCode;
                    LItem.ItemUID = UIItemList[i].ItemUID;
                    LItem.ItemName = UIItemList[i].ItemName;
                    LItem.ItemNum = (int)UIItemList[i].ItemNum;
                    LItem.ItemDim = UIItemList[i].Dim;
                    LItem.UIRemark = UIItemList[i].Remark;
                    if (ComputedUtils.JudgeItemIsScrew(UIItemList[i].ItemNameType))
                        LItem.ItemL = UIItemList[i].TheoryScrewH;
                    else
                    {
                        LItem.ItemL = UIItemList[i].TheoryH;
                        LItem.CGItemL = UIItemList[i].RealH;
                    }
                    quoInfo.ItemList.Add(LItem);
                }
            }
            quoInfo.LabourItemList = ShareItemData.UISurplusItemList;
            var quoContent = JsonConvert.SerializeObject(quoInfo).ToString();
            //原始全量数据
            info.quoInfo = quoContent;
            var processContent = JsonConvert.SerializeObject(pData).ToString();
            info.processInfo = processContent;
            info.selectAreaCondiInfo = JsonConvert.SerializeObject(ComputedUtils.dwgSelectAreaCondication(RecognizeUtils.TopViewPicCondiInfo,
                RecognizeUtils.AssemblyViewPicCondiInfo)).ToString();
            return info;
        }

        //记录 识别出来的全量信息
        [Serializable]
        public class AMTypeRQuoInfo
        {
            public List<BoardSectionItem> BoardList { set; get; } = new List<BoardSectionItem>();
            public List<LabourSingleItem> ItemList { set; get; } = new List<LabourSingleItem>();
            public List<LabourSingleItem> LabourItemList { set; get; } = new List<LabourSingleItem>();
            public AMTypeRQuoInfo()
            {

            }
        }

        //自动&手动 模式 上传记录信息
        [Serializable]
        public class AMTypeUPloadRecordInfo
        {
            //唯一标识
            public string UID { get; set; } = null;
            //客户编号
            public string customer { get; set; } = null;
            //批次号
            public string batchNum { get; set; } = null;
            //系统
            public string moldType { get; set; } = null;
            //花式
            public string fancy { get; set; } = null;
            //模号
            public string modeNum { get; set; } = null;
            //型号
            public string modeSize { get; set; } = null;
            //上传人编号
            public string jobNumber { get; set; } = null;
            //上传人名称
            public string jobNumberName { get; set; } = null;
            //文件打开路径(全路径)    
            public string dwgfilePath { get; set; } = null;
            //文件名
            public string dwgfileName { get; set; } = null;
            //原始全量数据副本
            public string quoInfo { get; set; } = null;
            //保存 上送到ERP的系统数据
            public string processInfo { get; set; } = null;
            //上传记录的时间
            public DateTime uploadTime { get; set; }
            //框选区域坐标信息
            public String selectAreaCondiInfo { get; set; }
            //上传模式 1自动 2手动 3 自动 中途记录 4手动 中途记录
            public int uploadType { get; set; } = 0;
        }

        //基础信息
        [Serializable]
        public class ModeBasicData
        {
            //客户
            public string Customer { get; set; }
            //2D这边的临时订单号
            public string tempOrderNumber { get; set; }
            //批次号
            public string BatchNum { get; set; }
            //花式
            public string FancyType { get; set; }
            //模号
            public string ModeNum { get; set; }
            //大小型号
            public string ModeSize { get; set; }
            //上传工号
            public string JobNumber { get; set; }
            //上传人员
            public ModeBasicData()
            {

            }
        }

        //文档系统 孔距接口全量参数
        public class GarbageSysHolePosData
        {
            public string moldSeries { get; set; }
            public string moldType { get; set; }
            public List<GarbageSysHolePosItem> holePartPositions { get; set; }
            public List<GarbageSysBoardItem> boardSizes { get; set; }
            public Boolean guidePinReverse { get; set; }
            public string sourceFrom { get; set; }
        }

        //文档系统 入参 零件孔距 单个
        public class GarbageSysHolePosItem
        {
            public string moldPart { get; set; }
            public int partDiam { get; set; }
            public int holeNum { get; set; }
            public int distanceWidth { get; set; }
            public int distanceLength { get; set; }
            public string partUid { get; set; }

            public string TranMoldPartArg(string ItemCode)
            {
                //导柱
                if (ItemCode.Equals("GuidePin"))
                    return "GUIDE_PIN";
                //拉杆
                if (ItemCode.Equals("SupportPin"))
                    return "SUPPORT_PIN"; ;
                if (ItemCode.Equals("NoNozzleMesonSupportPin"))
                    return "SUPPORT_PIN";
                //回针
                if (ItemCode.Equals("ReturnPin"))
                    return "RETURN_PIN";
                //中托边
                if (ItemCode.Equals("EGPPin"))
                    return "EGP";
                //⾯板螺丝
                if (ItemCode.Equals("TopPanelScrew"))
                    return "TOP_PANEL_SCREW";
                //底板螺丝
                if (ItemCode.Equals("BottomPanelScrew"))
                    return "BOTTOM_PANEL_SCREW";
                //针板螺丝
                if (ItemCode.Equals("PinBoardScrew"))
                    return "PIN_BOARD_SCREW";
                //方铁螺丝
                if (ItemCode.Equals("SpaceBlockScrew"))
                    return "SPACE_BLOCK_SCREW";
                return string.Empty;
            }

        }

        //文档系统 板 单个
        public class GarbageSysBoardItem
        {
            public string boardName { get; set; }
            public int boardNum { get; set; }
            public double width { get; set; }
            public double length { get; set; }
            public string TranBoardNameArg(string BoardCode)
            {
                if (BoardCode.Equals("aBoard"))
                    return "A";
                if (BoardCode.Equals("bBoard"))
                    return "B";
                //面板
                if (BoardCode.Equals("tpBoard"))
                    return "PANEL";
                //推板
                if (BoardCode.Equals("stBoard"))
                    return "PUSH";
                //⽔⼝推板
                if (BoardCode.Equals("rspBoard"))
                    return "PANEL_PUSH";
                //托板
                if (BoardCode.Equals("spBoard"))
                    return "SUPPORT";
                //底板
                if (BoardCode.Equals("bpBoard"))
                    return "BOTTOM";
                //⽅铁
                if (BoardCode.Equals("fangtie"))
                    return "SPACE_BLOCK";
                // 上针板
                if (BoardCode.Equals("fpBoard"))
                    return "UPPER_PIN";
                //下针板
                if (BoardCode.Equals("epBoard"))
                    return "BOTTOM_PIN";
                return string.Empty;
            }
        }

        //接收 文档系统 返回的数据
        public class GarbageSysResDataItem
        {
            public string partUid { get; set; }
            public int holeNum { get; set; }
            public string moldPart { set; get; }
            public int partDiam { set; get; }
            //孔距 
            public int distanceLength { set; get; }
            public int distanceWidth { set; get; }
            public List<CAD_Point> points { set; get; }
            //零件是否标准
            public Boolean standardFlag { set; get; }
        }

        //给ERP的全量加工数据
        [Serializable]
        public class ProcessData
        {
            //模架基础信息
            public ModeBasicData BasicData { get; set; } = new ModeBasicData();
            //额外判断信息
            public ExtraJudgeInfo ExtrajudgeInfo { get; set; } = new ExtraJudgeInfo();
            //板加工信息
            public List<ProcessBoard> BoardData { get; set; } = new List<ProcessBoard>();
            //板上的加工精框
            public List<FrameItem> FrameData { get; set; } = new List<FrameItem>();
            //零件的加工信息
            public List<ItemBaseParamData> ItemData { get; set; } = new List<ItemBaseParamData>();
            //ERP关注的加工项目信息
            public List<EGPProcessinfo> ERPProcessData { get; set; } = new List<EGPProcessinfo>();
            //ERP关注的加工清单
            public ProcessDetailListInfo processDetailListInfo { get; set; } = new ProcessDetailListInfo();
            //板加工面&加工面上孔&孔分中坐标
            public List<HoleMould> HoleProcessData { get; set; } = new List<HoleMould>();
            public ProcessData()
            {

            }
        }

        public class ItemBaseParamData
        {
            //排序类型规则 导柱 --导套--- 拉杆 -- 导套--回针--- 螺丝
            public int SortNo { get; set; }
            //零件类型
            public int ItemType { get; set; }
            //零件名称
            public string ItemName { get; set; }
            //零件长度
            public double Length { get; set; } = 0;
            //零件直径
            public double Dim { get; set; } = 0;
            //零件数量
            public int Num { get; set; } = 0;
            //零件备注
            public string Remark { get; set; } = "";

        }

        //给ERP的板加工数据   
        public class ProcessBoard
        {
            public int Seq_no { get; set; }
            public string Plate_Name { get; set; }
            public string Steel_Desc { get; set; }
            public string Steel_Code { get; set; }
            public double Thickness { get; set; }
            public double Width { get; set; }
            public double Length { get; set; }
            public double Qty { get; set; }
            public string Remark { get; set; }
            public Boolean Standard_Plate { get; set; }
            public Boolean Standard_Laring { get; set; }
            //拉令Dim
            public double LaringDim { get; set; } = 0;
            //拉令数量
            public int LaringNum { get; set; } = 0;
            //唯一标识
            public string BoardUID { get; set; }
            public string BoardCode { get; set; }
        }

        //额外的判断信息
        public class ExtraJudgeInfo
        {
            //导柱倒装 
            public Boolean gpRevFlag { get; set; } = false;
            //导柱过托
            public Boolean gpOverSpFlag { get; set; } = false;
            //回针过推
            public Boolean rpOverSpFlag { get; set; } = false;
        }

        public class RequestAutoQuoIdData
        {
            public int autoQuoId { get; set; }

            public RequestAutoQuoIdData()
            {

            }
        }

        //手动模式 零件信息 构建 孔加工类型 TO EDIT 
        public static HoleData MTypeBuildScrewHoleByItem(ManualItem Item, HoleProcessType PType)
        {
            HoleData HDItem = new HoleData();
            HDItem.Hole_Name = Item.ItemName;
            HDItem.TH = Item.holeArg.TH;
            HDItem.TD = Item.holeArg.TD;

            //螺丝
            if (JudgeItemTypeIsScrew(Item.ItemNameType))
            {
                //通牙孔
                if (PType == HoleProcessType.ThroughScrew)
                    HDItem.D = Convert.ToDecimal(Item.Dim);
                //通孔
                if (PType == HoleProcessType.ThroughHole)
                    HDItem.D = Convert.ToDecimal(Item.Dim);
                //盲牙孔
                if (PType == HoleProcessType.BlindScrew)
                    HDItem.D = Convert.ToDecimal(Item.Dim);
                //沉头孔
                if (PType == HoleProcessType.Sinkhead)
                    HDItem.D = Convert.ToDecimal(Item.Dim);
            }

            //非螺丝
            if (JudgeNoScrewButAboutItem(Item.ItemNameType))
            {
                //通孔
                if (PType == HoleProcessType.ThroughHole)
                    HDItem.D = Convert.ToDecimal(Item.Dim);
                //沉头孔
                if (PType == HoleProcessType.Sinkhead)
                    HDItem.D = Convert.ToDecimal(Item.Dim);
                //避空
                if (PType == HoleProcessType.BK_Hole)
                    HDItem.D = Convert.ToDecimal(Item.holeArg.BK);
            }

            //套
            if (JudgeItemTypeAboutBush(Item.ItemNameType))
            {
                //通孔
                if (PType == HoleProcessType.ThroughHole)
                    HDItem.D = Convert.ToDecimal(Item.holeArg.BushDim);
                //沉头孔
                if (PType == HoleProcessType.Sinkhead)
                    HDItem.D = Convert.ToDecimal(Item.holeArg.BushDim);
            }
            //HDItem.L = Item.ItemHL;
            //HDItem.W = Item.RealHoleX;
            //HDItem.Quantity = Item.RelScrewHoleList.Count;
            HDItem.process_Type = (int)PType;
            //导柱
            if (Item.ItemNameType == DItemNameType.GuidePin)
                HDItem.M_Type = (int)ItemProcessType.GuidePin;
            if (Item.ItemNameType == DItemNameType.NoNozzleMesonSupportPin)
                HDItem.M_Type = (int)ItemProcessType.GuidePin;
            //拉杆
            if (Item.ItemNameType == DItemNameType.SupportPin)
                HDItem.M_Type = (int)ItemProcessType.SupportPin;
            //回针
            if (Item.ItemNameType == DItemNameType.ReturnPin)
                HDItem.M_Type = (int)ItemProcessType.ReturnPin;
            //EGP
            if (Item.ItemNameType == DItemNameType.EGPPin)
                HDItem.M_Type = (int)ItemProcessType.EGP;
            //针板螺丝
            if (Item.ItemNameType == DItemNameType.PinBoardScrew)
                HDItem.M_Type = (int)ItemProcessType.PinBoardScrew;
            //面板螺丝
            if (Item.ItemNameType == DItemNameType.TopPanelScrew)
                HDItem.M_Type = (int)ItemProcessType.TopPanelScrew;
            //底板螺丝
            if (Item.ItemNameType == DItemNameType.BottomPanelScrew)
                HDItem.M_Type = (int)ItemProcessType.BottomPanelScrew;
            //方铁螺丝
            if (Item.ItemNameType == DItemNameType.SpaceBlockScrew)
                HDItem.M_Type = (int)ItemProcessType.SpaceBlockScrew;
            //回针螺丝 -> 公制螺丝
            if (Item.ItemNameType == DItemNameType.ReturnPinScrew)
                HDItem.M_Type = (int)ItemProcessType.GenericScrew;

            //什么零件套 -> 什么零件
            if (Item.ItemNameType == DItemNameType.GuideABush || Item.ItemNameType == DItemNameType.GuideBBush
                || Item.ItemNameType == DItemNameType.NoNozzleMesonSupportPinABush
                || Item.ItemNameType == DItemNameType.NoNozzleMesonSupportPinBBush)
                HDItem.M_Type = (int)ItemProcessType.GuidePin;

            if (Item.ItemNameType == DItemNameType.SupportPinABush
                || Item.ItemNameType == DItemNameType.SupportPinBBush)
                HDItem.M_Type = (int)ItemProcessType.SupportPin;

            return HDItem;
        }

        //自动模式 零件信息 构建 孔加工类型
        public HoleData ATypeBuildScrewHoleByItem(SingleItem Item, HoleProcessType PType)
        {
            HoleData HDItem = new HoleData();
            HDItem.Hole_Name = Item.ItemName;
            HDItem.TD = Item.InputTD;
            HDItem.TH = Item.InputTH;

            //螺丝
            if (JudgeItemTypeIsScrew(Item.ItemNameType))
            {
                //通牙孔
                if (PType == HoleProcessType.ThroughScrew)
                    HDItem.D = Convert.ToDecimal(Item.Dim);
                //通孔
                if (PType == HoleProcessType.ThroughHole)
                    HDItem.D = Convert.ToDecimal(Item.Dim);
                //盲牙孔
                if (PType == HoleProcessType.BlindScrew)
                    HDItem.D = Convert.ToDecimal(Item.Dim);
                //沉头孔
                if (PType == HoleProcessType.Sinkhead)
                    HDItem.D = Convert.ToDecimal(Item.Dim);
            }

            //非螺丝
            if (JudgeNoScrewButAboutItem(Item.ItemNameType))
            {
                //通孔
                if (PType == HoleProcessType.ThroughHole)
                    HDItem.D = Convert.ToDecimal(Item.Dim);
                //沉头孔
                if (PType == HoleProcessType.Sinkhead)
                    HDItem.D = Convert.ToDecimal(Item.Dim);
                //避空
                if (PType == HoleProcessType.BK_Hole)
                    HDItem.D = Convert.ToDecimal(Item.BK);
                if(PType == HoleProcessType.BKBlind)
                    HDItem.D = Convert.ToDecimal(Item.BK);
            }

            //套
            if (JudgeItemTypeAboutBush(Item.ItemNameType))
            {
                HDItem.D = Convert.ToDecimal(Item.InputBushSize);
                Boolean BBushF = Item.ItemCode.Contains("BBush");
                if (BBushF)
                {
                    HDItem.TD = Item.InputBushTD;
                    HDItem.TH = Item.InputBushTH;
                }
            }

            Boolean EGPBushF = Item.ItemNameType == DItemNameType.EGPBush;
            if (EGPBushF)
            {
                HDItem.D = Convert.ToDecimal(Item.InputBushSize);
                HDItem.TD = Item.InputBushTD + 1;
                HDItem.TH = Item.InputBushTH;
            }
            Boolean EGPF = Item.ItemNameType == DItemNameType.EGPPin;
            if(EGPF)
                HDItem.D = Convert.ToDecimal(Item.Dim);

            HDItem.L = Item.RealHoleY;
            HDItem.W = Item.RealHoleX;
            HDItem.Quantity = Item.RelScrewHoleList.Count;
            HDItem.process_Type = (int)PType;
            //导柱
            if (Item.ItemNameType == DItemNameType.GuidePin)
                HDItem.M_Type = (int)ItemProcessType.GuidePin;
            if (Item.ItemNameType == DItemNameType.NoNozzleMesonSupportPin)
                HDItem.M_Type = (int)ItemProcessType.GuidePin;
            //拉杆
            if (Item.ItemNameType == DItemNameType.SupportPin)
                HDItem.M_Type = (int)ItemProcessType.SupportPin;
            //回针
            if (Item.ItemNameType == DItemNameType.ReturnPin)
                HDItem.M_Type = (int)ItemProcessType.ReturnPin;
            //EGP
            if (Item.ItemNameType == DItemNameType.EGPPin)
                HDItem.M_Type = (int)ItemProcessType.EGP;
            //EGPBush 加工类型也入 EGP
            if (Item.ItemNameType == DItemNameType.EGPBush)
                HDItem.M_Type = (int)ItemProcessType.EGP;
            //针板螺丝
            if (Item.ItemNameType == DItemNameType.PinBoardScrew)
                HDItem.M_Type = (int)ItemProcessType.PinBoardScrew;
            //面板螺丝
            if (Item.ItemNameType == DItemNameType.TopPanelScrew)
                HDItem.M_Type = (int)ItemProcessType.TopPanelScrew;
            //底板螺丝
            if (Item.ItemNameType == DItemNameType.BottomPanelScrew)
                HDItem.M_Type = (int)ItemProcessType.BottomPanelScrew;
            //方铁螺丝
            if (Item.ItemNameType == DItemNameType.SpaceBlockScrew)
                HDItem.M_Type = (int)ItemProcessType.SpaceBlockScrew;
            //回针螺丝 -> 公制螺丝
            if (Item.ItemNameType == DItemNameType.ReturnPinScrew)
                HDItem.M_Type = (int)ItemProcessType.GenericScrew;

            //什么零件套 -> 什么零件
            if (Item.ItemNameType == DItemNameType.GuideABush || Item.ItemNameType == DItemNameType.GuideBBush
                || Item.ItemNameType == DItemNameType.NoNozzleMesonSupportPinABush
                || Item.ItemNameType == DItemNameType.NoNozzleMesonSupportPinBBush)
                HDItem.M_Type = (int)ItemProcessType.GuidePin;

            if (Item.ItemNameType == DItemNameType.SupportPinABush
                || Item.ItemNameType == DItemNameType.SupportPinBBush)
                HDItem.M_Type = (int)ItemProcessType.SupportPin;

            return HDItem;
        }


        //判断零件名称 和数据库 MC2_3DStandardHoleData Item 是否可以匹配(除中托边)
        public static Boolean JudgeNameMatchDBHoleName(DItemNameType NType)
        {
            if (NType == DItemNameType.GuidePin)
                return true;
            if (NType == DItemNameType.SupportPin)
                return true;
            if (NType == DItemNameType.NoNozzleMesonSupportPin)
                return true;
            if (NType == DItemNameType.ReturnPin)
                return true;
            if (NType == DItemNameType.PinBoardScrew)
                return true;
            if (NType == DItemNameType.TopPanelScrew)
                return true;
            if (NType == DItemNameType.BottomPanelScrew)
                return true;
            if (NType == DItemNameType.SpaceBlockScrew)
                return true;

            return false;
        }

        //判断零件类型是否为螺丝 还是其它
        public static Boolean JudgeItemTypeIsScrew(DItemNameType ItemType)
        {
            Boolean Flag1 = ItemType == DItemNameType.PinBoardScrew;
            Boolean Flag2 = ItemType == DItemNameType.TopPanelScrew;
            Boolean Flag3 = ItemType == DItemNameType.BottomPanelScrew;
            Boolean Flag4 = ItemType == DItemNameType.SpaceBlockScrew;
            Boolean Flag5 = ItemType == DItemNameType.ReturnPinScrew;
            Boolean Flag6 = ItemType == DItemNameType.MesonScrew;
            Boolean Flag7 = ItemType == DItemNameType.GenericScrew;
            return Flag1 || Flag2 || Flag3 || Flag4 || Flag5 || Flag6 || Flag7;
        }

        //判断零件中托边
        public static Boolean JudgeAboutEGP(DItemNameType ItemType)
        {
            return ItemType == DItemNameType.EGPPin || ItemType == DItemNameType.EGPBush;
        }


        //判断非螺丝但和零件相关
        public static Boolean JudgeNoScrewButAboutItem(DItemNameType ItemType)
        {
            Boolean Flag1 = ItemType == DItemNameType.GuidePin;
            Boolean Flag2 = ItemType == DItemNameType.SupportPin;
            Boolean Flag3 = ItemType == DItemNameType.NoNozzleMesonSupportPin;
            Boolean Flag4 = ItemType == DItemNameType.ReturnPin;
            Boolean Flag5 = ItemType == DItemNameType.EGPPin;
            Boolean Flag6 = ItemType == DItemNameType.Meson;
            Boolean Flag7 = ItemType == DItemNameType.ReturnPinScrewMeson;
            return Flag1 || Flag2 || Flag3 || Flag4 || Flag5 || Flag6 || Flag7;
        }

        public static Boolean JudgeIsGPOrRPItem(DItemNameType ItemType)
        {
            Boolean Flag1 = ItemType == DItemNameType.GuidePin;
            Boolean Flag2 = ItemType == DItemNameType.SupportPin;
            Boolean Flag3 = ItemType == DItemNameType.NoNozzleMesonSupportPin;
            Boolean Flag4 = ItemType == DItemNameType.ReturnPin;
            return Flag1 || Flag2 || Flag3 || Flag4;
        }

        //判断和套相关
        public static Boolean JudgeItemTypeAboutBush(DItemNameType ItemType)
        {
            Boolean Flag1 = ItemType == DItemNameType.GuideABush;
            Boolean Flag2 = ItemType == DItemNameType.GuideBBush;
            Boolean Flag3 = ItemType == DItemNameType.NoNozzleMesonSupportPinABush;
            Boolean Flag4 = ItemType == DItemNameType.NoNozzleMesonSupportPinBBush;
            Boolean Flag5 = ItemType == DItemNameType.SupportPinABush;
            Boolean Flag6 = ItemType == DItemNameType.SupportPinBBush;
            return Flag1 || Flag2 || Flag3 || Flag4 || Flag5 || Flag6;
        }

        public static T DeepCopy<T>(T obj)
        {
            return JsonConvert.DeserializeObject<T>(JsonConvert.SerializeObject(obj));
        }

        public static object DeepCopyObject(object obj)
        {
            if (obj == null) return null;
            object newCopy;
            if (obj.GetType().IsArray)
            {
                var t = obj.GetType();
                var e = t.GetElementType();
                var r = t.GetArrayRank();
                Array a = (Array)obj;
                newCopy = Array.CreateInstance(e, a.Length);
                Array n = (Array)newCopy;
                for (int i = 0; i < a.Length; i++)
                    n.SetValue(DeepCopyObject(a.GetValue(i)), i);
                return newCopy;
            }
            else
                newCopy = Activator.CreateInstance(obj.GetType(), true);

            foreach (var field in newCopy.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
            {
                if (!field.FieldType.IsPrimitive && field.FieldType != typeof(string))
                {
                    var fieldCopy = DeepCopyObject(field.GetValue(obj));
                    field.SetValue(newCopy, fieldCopy);
                }
                else
                    field.SetValue(newCopy, field.GetValue(obj));
            }
            return newCopy;
        }

        //对象 转换为Json字符串
        public static string toJson(object tablelList)
        {
            DataContractJsonSerializer json = new DataContractJsonSerializer(tablelList.GetType());
            string finJson = "";
            //序列化
            using (MemoryStream stream = new MemoryStream())
            {
                json.WriteObject(stream, tablelList);
                finJson = Encoding.UTF8.GetString(stream.ToArray());
            }
            return finJson;
        }

        //手动模式 计算板Z
        public static double ComputedMTypeMouldZ(string BoardUID)
        {
            double ResZ = 0;
            List<ManualBoardItem> BoardList = AssemblyShareData.MSectionList;
            int BIndex = BoardList.FindIndex(item => item.BoardUID.Equals(BoardUID));
            if (BIndex != -1)
            {
                List<ManualBoardItem> tempBList = BoardList.GetRange(0, BIndex);
                if (tempBList.Count > 0)
                    tempBList.ForEach(item => ResZ -= item.PlateThick);
                ResZ -= BoardList[BIndex].PlateThick / 2;
            }
            return ResZ;
        }

        //手动模式 补齐板加工依赖的基础参数
        public static List<ManualBoardItem> MtypePathBArg()
        {
            List<ManualBoardItem> ResBList = new List<ManualBoardItem>();
            double refW = 0;
            List<ManualBoardItem> BoardList = AssemblyShareData.MSectionList;
            int aBIndex = AssemblyShareData.MSectionList.FindIndex(item => item.BoardCode.Equals("aBoard"));
            if (aBIndex != -1)
                refW = AssemblyShareData.MSectionList[aBIndex].PlateWidth;
            for (int i = 0; i < BoardList.Count; i++)
            {
                ManualBoardItem tempB = (ManualBoardItem)DeepCopyObject(BoardList[i]);
                tempB.PArg.plateZ0 = Convert.ToDecimal(ComputedMTypeMouldZ(tempB.BoardUID));
                if (tempB.BoardCode.Equals("fangtie"))
                {
                    ManualBoardItem tempLF = new ManualBoardItem();
                    tempLF = (ManualBoardItem)DeepCopyObject(BoardList[i]);
                    ManualBoardItem tempRF = new ManualBoardItem();
                    tempRF = (ManualBoardItem)DeepCopyObject(BoardList[i]);
                    tempLF.Num = 1;
                    tempLF.PArg.plateX0 = (decimal)(-refW / 2 + tempLF.PlateWidth / 2);
                    tempLF.PArg.plateZ0 = Convert.ToDecimal(ComputedMTypeMouldZ(tempLF.BoardUID));
                    ResBList.Add(tempLF);
                    tempRF.Num = 1;
                    tempRF.PArg.plateX0 = (decimal)(-refW / 2 + tempLF.PlateWidth / 2);
                    tempRF.PArg.plateZ0 = Convert.ToDecimal(ComputedMTypeMouldZ(tempRF.BoardUID));
                    tempRF.PArg.plateX0 = (decimal)(refW / 2 - tempLF.PlateWidth / 2);
                    ResBList.Add(tempRF);
                }
                else
                    ResBList.Add(tempB);
            }
            return ResBList;
        }

        //手动模式 补齐零件加工依赖的基础参数
        public static void MTypePatchItemArg()
        {
            List<StandardGPSP> SPList = ParamsConfigData.StandardGPList;
            List<StandardGPSP> GPList = ParamsConfigData.StandardSPList;
            List<StandardRP> RPList = ParamsConfigData.StandardRPList;
            List<StandardScrew> ScrewList = ParamsConfigData.StandardScrewList;
            List<StandardEGP> EGPList = ParamsConfigData.StandardEGPList;
            List<ManualItem> MItemList = ShareItemData.MItemList;
            for (int i = 0; i < MItemList.Count; i++)
            {
                Boolean SPF = MItemList[i].ItemCode.Equals("SupportPin");
                Boolean GPF = MItemList[i].ItemCode.Equals("GuidePin");
                Boolean RPF = MItemList[i].ItemCode.Equals("ReturnPin");
                Boolean BushF = MItemList[i].ItemCode.Contains("Bush");
                Boolean ScrewF = MItemList[i].ItemCode.Contains("Screw");
                if (SPF)
                {
                    int SPIndex = SPList.FindIndex(item => item.Dimension == MItemList[i].Dim);
                    if (SPIndex != -1)
                    {
                        MItemList[i].holeArg.TD = SPList[SPIndex].TD;
                        MItemList[i].holeArg.TH = SPList[SPIndex].TH;
                    }
                }
                if (GPF)
                {
                    int GPIndex = GPList.FindIndex(item => item.Dimension == MItemList[i].Dim);
                    if (GPIndex != -1)
                    {
                        MItemList[i].holeArg.TD = GPList[GPIndex].TD;
                        MItemList[i].holeArg.TH = GPList[GPIndex].TH;
                    }
                }
                if (RPF)
                {
                    int RPIndex = RPList.FindIndex(item => item.Dimension == MItemList[i].Dim);
                    if (RPIndex != -1)
                    {
                        MItemList[i].holeArg.TD = RPList[RPIndex].TD;
                        MItemList[i].holeArg.TH = GPList[RPIndex].TH;
                    }
                }
                if (ScrewF)
                {
                    int sindex = ScrewList.FindIndex(item => item.Dimension == MItemList[i].Dim);
                    if (sindex != -1)
                    {
                        MItemList[i].holeArg.TD = ScrewList[sindex].TD;
                        MItemList[i].holeArg.TH = ScrewList[sindex].TH;
                    }
                }
                if (ScrewF)
                {
                    Boolean SPbushF = MItemList[i].ItemCode.Contains("SupportPin");
                    Boolean GPbushF = MItemList[i].ItemCode.Contains("GuidePin");
                    if (SPbushF)
                    {
                        int SPIndex = SPList.FindIndex(item => item.Dimension == MItemList[i].Dim);
                        if (SPIndex != -1)
                        {
                            MItemList[i].holeArg.BushDim = SPList[SPIndex].Dimension;
                            MItemList[i].holeArg.BushTH = SPList[SPIndex].BushTH;
                            MItemList[i].holeArg.TD = SPList[SPIndex].BushTD;
                        }
                    }
                    if (GPbushF)
                    {
                        int GPIndex = GPList.FindIndex(item => item.Dimension == MItemList[i].Dim);
                        if (GPIndex != -1)
                        {
                            MItemList[i].holeArg.BushDim = GPList[GPIndex].Dimension;
                            MItemList[i].holeArg.BushTH = GPList[GPIndex].BushTH;
                            MItemList[i].holeArg.TD = GPList[GPIndex].BushTD;
                        }
                    }
                }
            }
        }

        //手动模式 根据零件孔距 换算 临时分中坐标
        public static void MTypeSplitCoor()
        {
            ComputedUtils CU = new ComputedUtils();
            List<ManualItem> MItemList = ShareItemData.MItemList;
            for (int i = 0; i < MItemList.Count; i++)
            {
                MItemList[i].TempHPointList = new List<HPoint2D>();
                int ItemNum = MItemList[i].Num;
                decimal pxv = (decimal)(MItemList[i].ItemHW / 2);
                decimal pyv = (decimal)(MItemList[i].ItemHL / 2);
                if (ItemNum == 4)
                {
                    for (int j = 0; j < ItemNum; j++)
                    {
                        HPoint2D TL = new HPoint2D();
                        TL.X = -pxv;
                        TL.Y = pyv;
                        HPoint2D TR = new HPoint2D();
                        TL.X = pxv;
                        TL.Y = pyv;
                        HPoint2D BL = new HPoint2D();
                        TL.X = -pxv;
                        TL.Y = -pyv;
                        HPoint2D BR = new HPoint2D();
                        TL.X = pxv;
                        TL.Y = -pxv;
                        MItemList[i].TempHPointList.Add(TL);
                        MItemList[i].TempHPointList.Add(TR);
                        MItemList[i].TempHPointList.Add(BL);
                        MItemList[i].TempHPointList.Add(BR);
                    }
                }
                if (ItemNum == 6)
                {
                    for (int j = 0; j < ItemNum; j++)
                    {
                        HPoint2D TL = new HPoint2D();
                        TL.X = -pxv;
                        TL.Y = pyv;
                        HPoint2D TR = new HPoint2D();
                        TL.X = pxv;
                        TL.Y = pyv;
                        HPoint2D BL = new HPoint2D();
                        TL.X = -pxv;
                        TL.Y = -pyv;
                        HPoint2D BR = new HPoint2D();
                        TL.X = pxv;
                        TL.Y = -pxv;
                        //Center 2 P
                        HPoint2D CL = new HPoint2D();
                        CL.X = -pxv;
                        CL.Y = 0;
                        HPoint2D CR = new HPoint2D();
                        CL.X = pxv;
                        CL.Y = 0;
                        MItemList[i].TempHPointList.Add(TL);
                        MItemList[i].TempHPointList.Add(TR);
                        MItemList[i].TempHPointList.Add(BL);
                        MItemList[i].TempHPointList.Add(BR);
                        MItemList[i].TempHPointList.Add(CL);
                        MItemList[i].TempHPointList.Add(CR);
                    }
                }
                if (MItemList[i].TempHPointList.Count > 0)
                    MItemList[i].TempHPointList.ForEach(item => item.HoleName = CU.SetItemNameByType(MItemList[i].ItemNameType));
            }
        }


        //手动模式 根据零件长度 判断某个零件穿过了哪些板 (将BoardUID塞入零件) TO EDIT TO CHECK
        public static void MTypeMatchItemIncludeBoard(string ItemUID)
        {
            List<ManualBoardItem> BoardList = AssemblyShareData.MSectionList;

            List<ManualItem> ItemList = ShareItemData.MItemList;
            if (BoardList.Count > 0 && ItemList.Count > 0)
            {
                int ItemIndex = ItemList.FindIndex(item => item.ItemUID.Equals(ItemUID));
                if (ItemIndex != -1)
                {
                    string ItemCode = ItemList[ItemIndex].ItemCode;
                    double ItemRealL = ItemList[ItemIndex].L;
                    //面板螺丝
                    if (ItemCode.Equals("TopPanelScrew"))
                    {
                        List<string> BUIDList = new List<string>();
                        List<ManualBoardItem> operBList = (List<ManualBoardItem>)DeepCopyObject(BoardList);
                        int tpBIndex = operBList.FindIndex(item => item.BoardCode.Equals("tpBoard"));
                        if (tpBIndex != -1)
                        {
                            List<ManualBoardItem> tempList = operBList.GetRange(tpBIndex, operBList.Count - tpBIndex);
                            tempList = tempList.FindAll(item => !item.BoardCode.Equals("epBoard") || !item.BoardCode.Equals("fpBoard")).ToList();
                            double boardsThickSum = 0;
                            for (int i = 0; i < tempList.Count; i++)
                            {
                                boardsThickSum += tempList[i].PlateThick;
                                if (ItemRealL <= boardsThickSum)
                                {
                                    if (ItemRealL == boardsThickSum)
                                        BUIDList.Add(tempList[i].BoardUID);
                                    else
                                    {
                                        double Diff = boardsThickSum - ItemRealL;
                                        ItemList[ItemIndex].holeArg.PBArgInfo.NTTH = Diff;
                                        ItemList[ItemIndex].holeArg.PBArgInfo.NoThroughBoardUID = tempList[i].BoardUID;
                                    }
                                    break;
                                }
                                else
                                    BUIDList.Add(tempList[i].BoardUID);
                            }
                        }
                        if (BUIDList.Count > 0)
                        {
                            ItemList[ItemIndex].holeArg.PBArgInfo.ToochBoardUID = BUIDList[BUIDList.Count - 1];
                            BUIDList.RemoveAt(BUIDList.Count - 1);
                            if (BUIDList.Count > 0)
                            {
                                ItemList[ItemIndex].holeArg.PBArgInfo.TDBoardUID = BUIDList[0];
                                BUIDList.RemoveAt(0);
                                if (BUIDList.Count > 0)
                                    ItemList[ItemIndex].holeArg.PBArgInfo.ThroughBoardUIDList.AddRange(BUIDList);
                            }
                        }
                    }

                    //底板螺丝
                    if (ItemCode.Equals("BottomPanelScrew"))
                    {
                        int bpBIndex = BoardList.FindIndex(item => item.BoardCode.Equals("bpBoard"));
                        if (bpBIndex != -1)
                        {
                            List<string> BUIDList = new List<string>();
                            List<ManualBoardItem> operBList = (List<ManualBoardItem>)DeepCopyObject(BoardList);
                            operBList.Reverse();
                            operBList = operBList.FindAll(item => !item.BoardCode.Equals("epBoard")
                            && !item.BoardCode.Equals("fpBoard"));
                            double boardsThickSum = 0;
                            for (int i = 0; i < operBList.Count; i++)
                            {
                                if (ItemRealL == boardsThickSum)
                                    BUIDList.Add(operBList[i].BoardUID);
                                else
                                {
                                    double Diff = boardsThickSum - ItemRealL;
                                    ItemList[ItemIndex].holeArg.PBArgInfo.NTTH = operBList[i].PlateThick - Diff;
                                    ItemList[ItemIndex].holeArg.PBArgInfo.NoThroughBoardUID = operBList[i].BoardUID;
                                }
                                break;
                            }
                            if (BUIDList.Count > 0)
                            {
                                ItemList[ItemIndex].holeArg.PBArgInfo.ToochBoardUID = BUIDList[BUIDList.Count - 1];
                                BUIDList.RemoveAt(BUIDList.Count - 1);
                                if (BUIDList.Count > 0)
                                {
                                    ItemList[ItemIndex].holeArg.PBArgInfo.TDBoardUID = BUIDList[0];
                                    BUIDList.RemoveAt(0);
                                    if (BUIDList.Count > 0)
                                    {
                                        BUIDList.Reverse();
                                        ItemList[ItemIndex].holeArg.PBArgInfo.ThroughBoardUIDList.AddRange(BUIDList);
                                    }
                                }
                            }
                        }
                    }

                    //方铁螺丝
                    if (ItemCode.Equals("SpaceBlockScrew"))
                    {
                        int fIndex = BoardList.FindIndex(item => item.BoardCode.Equals("fangtie"));
                        if (fIndex != -1)
                        {
                            List<string> BUIDList = new List<string>();
                            List<ManualBoardItem> operBList = (List<ManualBoardItem>)DeepCopyObject(BoardList);
                            operBList.Reverse();
                            operBList = operBList.FindAll(item => !item.BoardCode.Equals("epBoard")
                            && !item.BoardCode.Equals("fpBoard"));
                            double boardsThickSum = 0;
                            for (int i = 0; i < operBList.Count; i++)
                            {
                                boardsThickSum += operBList[i].PlateThick;
                                if (ItemRealL == boardsThickSum)
                                    BUIDList.Add(operBList[i].BoardUID);
                                else
                                {
                                    double Diff = boardsThickSum - ItemRealL;
                                    ItemList[ItemIndex].holeArg.PBArgInfo.NTTH = operBList[i].PlateThick - Diff;
                                    ItemList[ItemIndex].holeArg.PBArgInfo.NoThroughBoardUID = operBList[i].BoardUID;
                                }
                                break;
                            }
                            if (BUIDList.Count > 0)
                            {
                                ItemList[ItemIndex].holeArg.PBArgInfo.ToochBoardUID = BUIDList[BUIDList.Count - 1];
                                BUIDList.RemoveAt(BUIDList.Count - 1);
                                if (BUIDList.Count > 0)
                                {
                                    ItemList[ItemIndex].holeArg.PBArgInfo.TDBoardUID = BUIDList[0];
                                    BUIDList.RemoveAt(0);
                                    if (BUIDList.Count > 0)
                                    {
                                        BUIDList.Reverse();
                                        ItemList[ItemIndex].holeArg.PBArgInfo.ThroughBoardUIDList.AddRange(BUIDList);
                                    }
                                }
                            }
                        }
                    }

                    //针板螺丝
                    if (ItemCode.Equals("PinBoardScrew"))
                    {
                        List<string> BUIDList = new List<string>();
                        List<ManualBoardItem> operBList = BoardList.GetRange(0, BoardList.Count);
                        operBList = operBList.FindAll(item => item.BoardCode.Equals("epBoard")
                        || item.BoardCode.Equals("fpBoard"));
                        //倒过来
                        operBList = operBList.OrderByDescending(item => item.MBSortNum).ToList();
                        double boardsThickSum = 0;
                        for (int i = 0; i < operBList.Count; i++)
                        {
                            boardsThickSum += operBList[i].PlateThick;
                            if (ItemRealL == boardsThickSum)
                                BUIDList.Add(operBList[i].BoardUID);
                            else
                            {
                                double Diff = boardsThickSum - ItemRealL;
                                ItemList[ItemIndex].holeArg.PBArgInfo.NTTH = operBList[i].PlateThick - Diff;
                                ItemList[ItemIndex].holeArg.PBArgInfo.NoThroughBoardUID = operBList[i].BoardUID;
                            }
                            break;
                        }
                        if (BUIDList.Count > 0)
                        {
                            ItemList[ItemIndex].holeArg.PBArgInfo.ToochBoardUID = BUIDList[BUIDList.Count - 1];
                            BUIDList.RemoveAt(BUIDList.Count - 1);
                            if (BUIDList.Count > 0)
                            {
                                ItemList[ItemIndex].holeArg.PBArgInfo.TDBoardUID = BUIDList[0];
                                BUIDList.RemoveAt(0);
                                if (BUIDList.Count > 0)
                                {
                                    BUIDList.Reverse();
                                    ItemList[ItemIndex].holeArg.PBArgInfo.ThroughBoardUIDList.AddRange(BUIDList);
                                }
                            }
                        }
                    }

                    //回针
                    if (ItemCode.Equals("ReturnPin"))
                    {
                        List<string> BUIDList = new List<string>();
                        int epIndex = BoardList.FindLastIndex(item => item.BoardCode.Equals("epBoard"));
                        if (epIndex != -1)
                        {
                            int fangtieIndex = BoardList.FindIndex(item => item.BoardCode.Equals("fangtie"));
                            if (fangtieIndex != -1)
                            {
                                double fangtieH = BoardList[fangtieIndex].PlateThick;
                                List<ManualBoardItem> epfpList = BoardList.FindAll(item => item.BoardCode.Equals("epBoard")
                                || item.BoardCode.Equals("fpBoard"));
                                double allepfpH = epfpList.Sum(item => item.PlateThick);
                                //中间镂空部分的H差
                                double diffepfpH = fangtieH - allepfpH + BoardList[epIndex].PlateThick;
                                ItemList[ItemIndex].holeArg.PBArgInfo.TDBoardUID = BoardList[epIndex].BoardUID;
                                //看剩下的长度能穿哪些板
                                double otherH = ItemRealL - diffepfpH;
                                List<ManualBoardItem> tempList = BoardList.GetRange(0, fangtieIndex);
                                tempList = tempList.OrderByDescending(item => item.MBSortNum).ToList();
                                double otherboardsThickSum = 0;
                                for (int i = 0; i < tempList.Count; i++)
                                {
                                    otherboardsThickSum += tempList[i].PlateThick;
                                    if (otherH <= otherboardsThickSum)
                                    {
                                        if (otherH == otherboardsThickSum)
                                            BUIDList.Add(tempList[i].BoardUID);
                                        else
                                        {
                                            double Diff = otherboardsThickSum - otherH;
                                            ItemList[ItemIndex].holeArg.PBArgInfo.NTTH = tempList[i].PlateThick - Diff;
                                            ItemList[ItemIndex].holeArg.PBArgInfo.NoThroughBoardUID = tempList[i].BoardUID;
                                        }
                                        break;
                                    }
                                    else
                                        BUIDList.Add(tempList[i].BoardUID);
                                }
                                if (BUIDList.Count > 0)
                                {
                                    BUIDList.Reverse();
                                    ItemList[ItemIndex].holeArg.PBArgInfo.ThroughBoardUIDList.AddRange(BUIDList);
                                }
                            }
                        }
                    }

                    //拉杆
                    if (ItemCode.Equals("SupportPin") || ItemCode.Equals("NoNozzleMesonSupportPin"))
                    {
                        List<string> BUIDList = new List<string>();
                        List<ManualBoardItem> operBList = BoardList.GetRange(0, BoardList.Count);
                        double boardsThickSum = 0;
                        for (int i = 0; i < operBList.Count; i++)
                        {
                            boardsThickSum += operBList[i].PlateThick;
                            if (ItemRealL == boardsThickSum)
                                BUIDList.Add(operBList[i].BoardUID);
                            else
                            {
                                double Diff = boardsThickSum - ItemRealL;
                                ItemList[ItemIndex].holeArg.PBArgInfo.NTTH = operBList[i].PlateThick - Diff;
                                ItemList[ItemIndex].holeArg.PBArgInfo.NoThroughBoardUID = operBList[i].BoardUID;
                            }
                            break;
                        }
                        if (BUIDList.Count > 0)
                        {
                            ItemList[ItemIndex].holeArg.PBArgInfo.TDBoardUID = BUIDList[0];
                            BUIDList.RemoveAt(0);
                            if (BUIDList.Count > 0)
                            {
                                BUIDList.Reverse();
                                ItemList[ItemIndex].holeArg.PBArgInfo.ThroughBoardUIDList.AddRange(BUIDList);
                            }
                        }
                    }

                    //导柱 后续考虑正反装 套
                    if (ItemCode.Equals("GuidePin"))
                    {
                        //Boolean GPInverF = DataForm.MGPInverBox.Value;
                        Boolean GPInverF = true;
                        List<string> BUIDList = new List<string>();
                        //导柱穿过的板 A-B板之间
                        int aIndex = BoardList.FindIndex(item => item.BoardCode.Equals("aBoard"));
                        int bIndex = BoardList.FindLastIndex(item => item.BoardCode.Equals("bBoard"));
                        if (aIndex != -1 && bIndex != -1)
                        {
                            List<ManualBoardItem> operBList = BoardList.GetRange(aIndex, bIndex - aIndex + 1);
                            double boardsThickSum = 0;
                            for (int i = 0; i < operBList.Count; i++)
                            {
                                boardsThickSum += operBList[i].PlateThick;

                                if (ItemRealL <= boardsThickSum)
                                {
                                    if (ItemRealL == boardsThickSum)
                                        BUIDList.Add(operBList[i].BoardUID);
                                    else
                                    {
                                        double Diff = boardsThickSum - ItemRealL;
                                        ItemList[ItemIndex].holeArg.PBArgInfo.NTTH = operBList[i].PlateThick - Diff;
                                        ItemList[ItemIndex].holeArg.PBArgInfo.NoThroughBoardUID = operBList[i].BoardUID;
                                    }
                                    break;
                                }
                                else
                                    BUIDList.Add(operBList[i].BoardUID);
                            }
                            if (BUIDList.Count > 0)
                            {
                                //反装
                                if (GPInverF)
                                {
                                    ItemList[ItemIndex].holeArg.PBArgInfo.TDBoardUID = BUIDList[0];
                                    BUIDList.RemoveAt(0);
                                    if (BUIDList.Count > 0)
                                    {
                                        BUIDList.Reverse();
                                        ItemList[ItemIndex].holeArg.PBArgInfo.ThroughBoardUIDList.AddRange(BUIDList);
                                    }
                                }
                                //正装
                                else
                                {
                                    ItemList[ItemIndex].holeArg.PBArgInfo.TDBoardUID = BUIDList[BUIDList.Count - 1];
                                    BUIDList.RemoveAt(BUIDList.Count - 1);
                                    if (BUIDList.Count > 0)
                                        ItemList[ItemIndex].holeArg.PBArgInfo.ThroughBoardUIDList.AddRange(BUIDList);
                                }
                            }
                        }
                    }

                    //EGP TO EDIT
                    if (ItemCode.Equals("EGPPin"))
                    {
                        ItemList[ItemIndex].BoardUIDList = new List<string>();
                        int startIndex = BoardList.FindLastIndex(item => item.BoardCode.Equals("spBoard"));
                        startIndex = BoardList.FindLastIndex(item => item.BoardCode.Equals("bBoard"));
                        if (startIndex != -1)
                        {
                            List<ManualBoardItem> tempList = BoardList.GetRange(startIndex, BoardList.Count - startIndex);
                            List<ManualBoardItem> epfpList = tempList.FindAll(item => item.BoardCode.Equals("epBoard")
                            || item.BoardCode.Equals("fpBoard"));
                            if (epfpList.Count > 0)
                                epfpList.ForEach(item => ItemList[ItemIndex].BoardUIDList.Add(item.BoardUID));
                            List<ManualBoardItem> fangtieList = tempList.FindAll(item => item.BoardCode.Equals("fangtie"));
                            if (fangtieList.Count > 0)
                                fangtieList.ForEach(item => ItemList[ItemIndex].BoardUIDList.Add(item.BoardUID));
                            List<ManualBoardItem> otherList = tempList.FindAll(item => !item.BoardCode.Equals("epBoard")
                            && !item.BoardCode.Equals("fpBoard") && !item.BoardCode.Equals("fangtie"));
                            if (otherList.Count > 0)
                                otherList.ForEach(item => ItemList[ItemIndex].BoardUIDList.Add(item.BoardUID));
                        }
                    }

                    //套 can not computed Hole By Length
                    if (ItemCode.Contains("Bush"))
                    {
                        ItemList[ItemIndex].holeArg.PBArgInfo.ThroughBoardUIDList = new List<string>();
                        string IBUID = ItemList[ItemIndex].Remark;
                        int targetBIndex = BoardList.FindIndex(item => item.BoardUID.Equals(IBUID));
                        if (targetBIndex != -1)
                        {
                            //double bushTH = BoardList[targetBIndex].PlateThick;
                            //if (ItemCode.Contains("ABush"))
                            //    ItemList[ItemIndex].holeArg.BushTH = (decimal)bushTH;
                            //if (ItemCode.Contains("BBush"))
                            //    ItemList[ItemIndex].holeArg.Bush = (decimal)bushTH;
                            ItemList[ItemIndex].holeArg.PBArgInfo.ThroughBoardUIDList.Add(BoardList[targetBIndex].BoardUID);
                        }


                    }

                }
            }
        }

        //手动模式 设置每件板 孔距是否标准
        public static void MTypeSetBoardHoleStandard()
        {
            List<ManualBoardItem> BoardList = AssemblyShareData.MSectionList;
            List<ManualItem> ItemList = ShareItemData.MItemList;
            if (BoardList.Count > 0 && ItemList.Count > 0)
            {
                for (int i = 0; i < BoardList.Count; i++)
                {
                    string tempBoardUID = BoardList[i].BoardUID;
                    List<ManualItem> tempAllItemList = ItemList.FindAll(item => item.BoardUIDList.Contains(tempBoardUID)).ToList();
                    tempAllItemList = tempAllItemList.FindAll(item => !item.ItemCode.Equals("EGPPin")).ToList();
                    //判断除EGP外的零件标准
                    if (tempAllItemList.Count > 0)
                    {
                        int allNum = tempAllItemList.Count;
                        List<ManualItem> tempStandardItemList = tempAllItemList.FindAll(item => item.HoleIsStandard
                        == StandardType.Standard).ToList();
                        int SNum = tempStandardItemList.Count;
                        if (allNum != SNum)
                            BoardList[i].PitchHoleStandard = StandardType.NonStandard;
                        else
                            BoardList[i].PitchHoleStandard = StandardType.Standard;
                    }
                    //判断EGP
                    List<ManualItem> egpItemList = ItemList.FindAll(item => item.ItemCode.Equals("EGPPin")).ToList();
                    if (egpItemList.Count > 0)
                    {
                        int allegpnum = egpItemList.Count;
                        int standardegpnum = 0;
                        Boolean BhasEGPF = false;
                        for (int j = 0; j < egpItemList.Count; j++)
                        {
                            Boolean EGPF = egpItemList[j].BoardUIDList.Contains(tempBoardUID);
                            if (EGPF)
                            {
                                BhasEGPF = true;
                                if (egpItemList[j].HoleIsStandard == StandardType.Standard)
                                    standardegpnum++;
                            }
                        }
                        //EGP穿过该板
                        if (BhasEGPF)
                        {
                            if (allegpnum != standardegpnum)
                                BoardList[i].EGPPitchHoleStandard = StandardType.NonStandard;
                            else
                                BoardList[i].EGPPitchHoleStandard = StandardType.Standard;
                        }
                    }
                }
            }
        }
    }


}
